Wednesday, June 1, 2011

Updating AIR applications: Part 1

Today we'll learn about updating AIR applications.

If you have developed an AIR application and are distributing it, you probably will make updates/fixes/patches etc. to it. By making updates you let the users that didn't have your application installed download the already updated version of it, and you let the users that already have this application installed updated without them needing to uninstall it and reinstall the latest version.

There are 2 ways of distributing updates for your application. The first one is called passive - this is when you, the developer, only update your site/webspace with new versions of the application, that users can download. The second way is the active way - that's when your application automatically checks for updates, then notifies the user that an update is available and automatically installs the update.

To manage updates the passive way, all you have to do as a developer is update your site with the new .air files, that the users can download. No other actions are needed from your side.

But if you want the application to handle the updates automatically, you'll need to do more than just update the .air file. Your application must be able to do these steps:

  1. Send a request to an online service that holds information about what is the latest application version. This service needs to be available in the network as an AMF, REST, SOAP or a similar service, so that your application can refer to it using the standard Flash Player network functions.0
  2. Compare the installed application's version and the latest version, and then find out if we need to update our application.
  3. If we need to update, notify the user that an update is available (or don't) and download the .air file to the user's computer.
  4. Run the .air file using an flash.desktop.Updater object.

In this tutorial we'll learn how to use the Updater class.

The Updater class is used to update AIR applications. To use it, we need to create an Updater object and call an update() method. We need to pass 2 parameters: a reference to the .air file on the user's computer, and a string value that represents the version of the application.

For example, if we have a new version of our AIR application available and downloaded to the hard drive, we can use the following code in a previous version of the application to update itself.

var file:File = File.documentsDirectory.resolvePath("myApp_version2.air");
var updater:Updater = new Updater();
updater.update(file, "2.0");

What this does:

  1. Stops the current version of AIR application from working.
  2. Checks, whether the application IDs and publisher IDs in the current .air and the new .air files are the same.
  3. Checks, whether the version passed as the second parameter of update() is the same as the one that is specified in that .air file.
  4. Installs the new version of the application if the steps above were successful.
  5. Runs the new version.

If there has been an error on any of the steps, the previous version is opened instead of the new one.

That's all for today.

Thanks for reading!


Updating AIR applications: Part 2
Updating AIR applications: Part 3

No comments:

Post a Comment