AIR之自动更新

AIR自动更新的原理其实很简单,ApplicationUpdaterUI会去读取网络上的一个版本描述文件,描述文件事是一个特定的XML文档,其中包含了版本号和对应的安装文件路径以及更新描述信息。然后和当前运行的AIR程序版本进行比较,来决定是否下载和安装。

 

如何成功配置AIR自动升级?大致可分为2个步骤:

 

1.ActionScript:

<?xml version="1.0" encoding="utf-8"?> <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" creationComplete="versionCheck();"> <fx:Script> <!--[CDATA[ import air.update.ApplicationUpdaterUI; import air.update.events.UpdateEvent; private function versionCheck():void { //显示当前版本号 var appXml:XML = NativeApplication.nativeApplication.applicationDescriptor; var ns:Namespace = appXml.namespace(); txt.text += appXml.ns::version; //Update var appUpdate:ApplicationUpdaterUI = new ApplicationUpdaterUI(); appUpdate.updateURL = "http://localhost/AIR_Update/update.xml"; appUpdate.isCheckForUpdateVisible = false; appUpdate.isFileUpdateVisible = false; appUpdate.isInstallUpdateVisible = false; appUpdate.addEventListener(UpdateEvent.INITIALIZED, onUpdateHandler); appUpdate.addEventListener(ErrorEvent.ERROR, onErrorHandler); appUpdate.initialize(); trace(appUpdate.currentVersion); } /** * onUpdateHandler * 自动更新初始化 * * @param UpdateEvent evt * @return void * **/ private function onUpdateHandler(evt:UpdateEvent):void { var target:ApplicationUpdaterUI = evt.currentTarget as ApplicationUpdaterUI; target.removeEventListener(UpdateEvent.INITIALIZED, onUpdateHandler); target.removeEventListener(ErrorEvent.ERROR, onErrorHandler); target.checkNow(); } /** * onErrorHandler * 自动更新错误处理 * * @param ErrorEvent evt * @return void * **/ private function onErrorHandler(evt:ErrorEvent):void { var target:ApplicationUpdaterUI = evt.currentTarget as ApplicationUpdaterUI; target.removeEventListener(UpdateEvent.INITIALIZED, onUpdateHandler); target.removeEventListener(ErrorEvent.ERROR, onErrorHandler); trace(evt.toString()); } ]]--> </fx:Script> <fx:Declarations> <!-- 将非可视元素(例如服务、值对象)放在此处 --> </fx:Declarations> <s:layout> <s:VerticalLayout verticalAlign="middle" horizontalAlign="center"/> </s:layout> <s:Label text="Hello World" fontSize="15" fontWeight="bold"/> <s:Label id="txt" text="Version Update:" fontSize="15" fontWeight="bold"/> </s:WindowedApplication>

 

 

2.服务器上的update.xml文件配置

<?xml version="1.0" encoding="utf-8"?> <update xmlns="http://ns.adobe.com/air/framework/update/description/1.0"> <version>1.2</version> <url>http://localhost/AIR_Update/AIR_VersionUpdate.air</url> <description> <text xml:lang="en_US">AIR AutoUpdate</text> <text xml:lang="zh_CN">AIR 自动更新</text> </description> </update>

 

PS:

有几个需要注意的不得不提醒一下。
需要Flex SDK 3.2才支持AIR 1.5

XML中的版本号和指定的AIR程序的版本号一定要保证匹配,比如1.0千万不要写成了1.00了。

 

你可能感兴趣的:(xml,function,Flex,library,AIR,encoding)