如何使用Adobe AIR更新框架

Using the Update Framework for Adobe AIR

如何使用Adobe AIR更新框架

One feature that I was more useful in Adobe AIR, was the addition of an API designed to make better automatic update of my application. This can be very important because not all users have the time (or desire) to return the application site to download the latest version.

在Adobe AIR中有一个我觉得非常有用的特征,这个特性被设计用于自动更新你的程序,以使你的程序更加完善.这是非常重要的一点,因为不是所有用户都会回到网站去下载最新版本.

This is already routine for operating systems and software that we use in day-to-day as the Mozilla Firefox and Google Chrome or TweetDeck.

这个功能对于每天更新的操作系统和软件如Mozilla Firefox 和Google Chrome 或TweetDeck是很常见的.

From Adobe AIR 1.5, we have the class ApplicationUpdater andApplicationUpdaterUI which aims to define the basic functionality to update the applications made with Adobe AIR

Manage updates and can be tricky, AIR update framework has the API’s necessary for you to do this in a practical and functional. The developer can, for example:

Adobe AIR 1.5开始,我们有ApplicationUpdater 和ApplicationUpdaterUI ,这些类定义了用于更新Adobe AIR 制作的应用程序的基础方法.管理更新应该是非常棘手的,AIR 更新框架包含了实用功能的API.开发者可以使用这些,如下面例子:

  • Periodically checking for updates based on an interval or at the request of the user 根据某一时间间隔或用户要求,定期检查更新
  • Downloading AIR files (updates) from a web source 从网站服务器上下载要更新的AIR 文件
  • Alerting the user on the first run of the newly installed version 在首次运行的时候提醒用户使用最新版本
  • Confirming that the user wants to check for updates 确认用户想要检查的更新
  • Displaying information on the new update version to the user 在给用户更新的版本中显示信息
  • Displaying download progress and error information to the user 显示下载进度以及错误信息给用户

The information is derived from XML files where you say that the latest version of software, new version of the news etc. Let’s take a practical example, if you use Flash Builder should already have the files applicationupdater.swc and applicationupdater_ui.swc as a reference in the library.

信息从xml文件中获得,xml文件里面说明了软件的最新版本,以及新版本的新闻等等.让我们做一个实用的例子,如果你使用Flash Builder 可能已经获得了applicationupdater.swc 和applicationupdater_ui.swc 两个文件在库中.
We started by calling xml updateConfig.xml, that “say” to your application where are the files to update.

我们开始查看叫updateConfig.xml 文件,它告诉你的应用更新文件在那里.

PLAIN TEXT

XML:

  1. <?xml version=”1.0″ encoding=”utf-8″?>
  2. <configuration xmlns=”http://ns.adobe.com/air/framework/update/configuration/1.0&#8243;>
  3.      <url>http://localhost:81/leonardofranca/air/updates/testeUpdate/updateDescriptor.xml</url>
  4.     <delay>1</delay>
  5. </configuration>

It must be saved in the same directory of your application, along with other xml and swf files. Now in Flex, instantiate the class ApplicationUpdateUI and setting the configuration xml file so that Flex can know where is the update.

这个文件必须存在你应用程序的同一目录下,并且同其他xml及swf文件放置一起.当前在Flex中, 实例类 ApplicationUpdateUI 以及设定配置xml文件,这样Flex将会知道更新文件在哪里.

PLAIN TEXT

ACTIONSCRIPT3:

  1. var appUpdater:ApplicationUpdaterUI = new ApplicationUpdaterUI();
  2. appUpdater.configurationFile = new File(“app:/updateConfig.xml”);
  3. appUpdater.initialize();
  4. //via ActionScript
  5. //appUpdater.updateURL = ” http://example.com/updates/update.xml&#8221;;
  6. //appUpdater.delay = 1;

The file updateDescriptor.xml is where you set the version in the update of your application and where you can add a description of the news update.

updateDescriptor.xml 文件用于你设定在你更新的应用中的版本,以及添加一个更新的描述.

PLAIN TEXT

XML:

  1. <?xml version=”1.0″ encoding=”utf-8″?>
  2.      <update xmlns=”http://ns.adobe.com/air/framework/update/description/2.5&#8243;>
  3.        <versionNumber>0.0.2</versionNumber>
  4.        <url>http://localhost:81/leonardofranca/air/updates/testeUpdate/testeUpdate_0.0.2.air</url>
  5.        <description><![CDATA[
  6. This version has fixes for the following knowns issues:
  7. *First issue
  8. *Second issue
  9.  ]]></description>
  10.     </update>

Basically that’s it, we will only implement the call to open the application, it checks if there is update.

基本上就是这样,我们将会只执行调用来打开应用,它会检查是否有更新.

PLAIN TEXT

MXML:

  1. <?xml version=”1.0″ encoding=”utf-8″?>
  2. <s:WindowedApplication xmlns:fx=”http://ns.adobe.com/mxml/2009&#8243;
  3.                        xmlns:s=”library://ns.adobe.com/flex/spark”
  4.                        xmlns:mx=”library://ns.adobe.com/flex/mx” creationComplete=”windowedapplication1_creationCompleteHandler(event)”>
  5.     <fx:Script>
  6.         <![CDATA[
  7.             import air.update.ApplicationUpdaterUI;
  8.             import air.update.events.UpdateEvent;
  9.             import mx.events.FlexEvent;
  10.             private var appUpdater:ApplicationUpdaterUI;
  11.             protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void
  12.             {
  13.                 appUpdater = new ApplicationUpdaterUI();
  14.                 appUpdater.configurationFile = new File(“app:/updateConfig.xml”);
  15.                 appUpdater.addEventListener(ErrorEvent.ERROR, onError);
  16.                 appUpdater.addEventListener(UpdateEvent.INITIALIZED, handlerInit);
  17.                 appUpdater.initialize();
  18.                 //via ActionScript
  19.                 //appUpdater.updateURL = ” http://example.com/updates/update.xml&#8221;;
  20.                 //appUpdater.delay = 1;
  21.             }
  22.             protected function onError(event:ErrorEvent):void
  23.             {
  24.                 trace(event.text);
  25.             }
  26.             protected function handlerInit(event:UpdateEvent):void
  27.             {
  28.                 appUpdater.checkNow();
  29.             }
  30.         ]]>
  31.     </fx:Script>
  32.     <fx:Declarations>
  33.         <!– Place non-visual elements (e.g., services, value objects) here –>
  34.     </fx:Declarations>
  35. </s:WindowedApplication>

I created a second version of my test application for demonstration, we have the following result:

我创建了一个my test 应用第二版,用于示范,我们将会见到下面的结果:

Check for update

If you want to see if there are any updates of the application, just click on “check for upadates. The updated file is downloaded and installed.

如果你想看看是否有任何可以更新的应用程序,只需要点击”检查更新”.更新文件将会被下载和安装.

 

References:

http://help.adobe.com/en_US/air/build/WS9CD40F06-4DD7-4230-B56A-88AA27541A1E.html
http://www.adobe.com/devnet/air/flex/quickstart/articles/update_framework.html

 

Advertisements

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: