我正在学习AIR应用程序的自动更新功能。我创建了一个无效的简单应用程序。代码如下:
<?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="checkForUpdate()" >
<fx:Script><![CDATA[
import air.update.ApplicationUpdaterUI;
import air.update.events.UpdateEvent;
private var appUpdater:ApplicationUpdaterUI=new ApplicationUpdaterUI();
private function checkForUpdate():void
{
setApplicationVersion();
appUpdater.delay = 1;
appUpdater.isDownloadProgressVisible = true;
appUpdater.isDownloadUpdateVisible = true
appUpdater.isInstallUpdateVisible = true;
appUpdater.isFileUpdateVisible = true;
appUpdater.updateURL = "http://localhost:8081/DynamicWeb/release/update.xml";
appUpdater.isCheckForUpdateVisible = false;
appUpdater.addEventListener(UpdateEvent.INITIALIZED, onUpdate);
appUpdater.addEventListener(ErrorEvent.ERROR, onError);
appUpdater.initialize();
}
}
// Find the current version for our Label below
private function setApplicationVersion():void
{
var appXML:XML = NativeApplication.nativeApplication.applicationDescriptor;
var ns:Namespace = appXML.namespace();
lbl.text = "Current version is " + appXML.ns::version;
//Common.helpDetails = appXML.ns::versionLabel;
}
private function onError(event:ErrorEvent):void
{
//Alert.show(event.toString());
}
private function onUpdate(event:UpdateEvent):void
{
appUpdater.checkNow(); // Go check for an update now }
}
]]></fx:Script>
<s:HGroup x="89" y="124" width="413" height="34">
<s:Label id="lbl" />
</s:HGroup>
</s:WindowedApplication>
*最初在AutoUpdate-app.xml和update.xml文件中,版本标签设置为1.0.0
<?xml version="1.0" encoding="UTF-8"?>
<update xmlns="http://ns.adobe.com/air/framework/update/description/1.0">
<version>1.0.0</version>
<url>http://localhost:8081/DynamicWeb/release/Update_air.air</url>
<description><![CDATA[
Typically, this is used to summarize what's new in the release
]]></description>
</update>
我正在研究AIR 3.1
它没有给出任何错误。只有更新窗口不起作用。
请告诉我我做错了什么。感谢。
答案 0 :(得分:0)
1)跟踪真实版本和update.xml,并确保你做得正确。您必须确保使用1.0.0版本运行旧应用程序。顺便说一句,您可以使用属性ApplicationUpdaterUI.currentVersion
代替NativeApplication.nativeApplication.applicationDescriptor
2)在checkNow()调用后你不会监听事件。聆听所有事件,例如本文。在
http://thanksmister.com/2009/09/13/custom-air-updater-interface-using-applicationupdater/(参见 UpdateManager.as #initialize()):
appUpdater.addEventListener(UpdateEvent.INITIALIZED, updaterEvent);
appUpdater.addEventListener(StatusUpdateEvent.UPDATE_STATUS, updaterEvent);
appUpdater.addEventListener(UpdateEvent.BEFORE_INSTALL, updaterEvent);
appUpdater.addEventListener(StatusUpdateErrorEvent.UPDATE_ERROR, updaterEvent);
appUpdater.addEventListener(UpdateEvent.DOWNLOAD_START, updaterEvent);
appUpdater.addEventListener(ProgressEvent.PROGRESS, updaterEvent);
appUpdater.addEventListener(UpdateEvent.DOWNLOAD_COMPLETE, updaterEvent);
appUpdater.addEventListener(DownloadErrorEvent.DOWNLOAD_ERROR, updaterEvent);
appUpdater.addEventListener(ErrorEvent.ERROR, updaterEvent);
private function updaterEvent(event : Event) : void {
trace(event.type);
}
可能,你错过了一些事情......
答案 1 :(得分:0)
在服务器端update.xml中,您应该将标记版本替换为 versionNumber 。 自AIR 2.5以来,这一情况发生了变化。