Air app Updates

Source: Internet
Author: User

Preparation: Update.xml,xxx.air Two files are stored in the Server update directory

Update.xml

<update xmlns="http://ns.adobe.com/air/framework/update/description/2.5"><versionNumber> 0.0.1</versionnumber><url>http://localhost:8080/update/xxx.air</url> <description/></update>

Check for Updates

//reading configuration Files         Public functionReadconfig ():void        {            //get the version numberAppupdater=NewApplicationupdater (); Global.getinstance (). CurrentVersion=appupdater.currentversion; varUrlload:urlloader=NewURLLoader (); Urlload.load (Newurlrequest ("Http://localhost:8080/update/update.xml"));       Urlload.addeventlistener (httpstatusevent.http_status,checkfunction); } protectedfunctionCheckfunction (event:httpstatusevent):void        {            if(Event.status = = 200) {checkversion (); }            Else            {                 This. dispatchevent (NewEvent (event.complete));
If the network does not work, skip the update}} //Check for version Automatic UpdatesProtectedfunctionCheckversion ():void{beetleApp.startPage.Tips="Detecting version updates ..."; NativeApplication.nativeApplication.addEventListener (event.exiting,function(e:event):void { varOpened:array =NativeApplication.nativeApplication.openedWindows; for(varI:int = 0; i < opened.length; i + +) {opened[i].close (); } }); The difference is whether there is a hint//appupdater = new Applicationupdater ();appupdater.isnewerversionfunction=isnewerversionfunction; //appupdater.configurationfile = configurationfile; //appupdater.ischeckforupdatevisible = false;Appupdater.updateurl =Constants.update_url; Appupdater.addeventlistener (updateevent.initialized, updaterinitialized); Appupdater.addeventlistener (Statusupdateevent.update_status, statusupdate); Appupdater.addeventlistener (Updateevent.before_install, Beforeinstall); Appupdater.addeventlistener (Statusupdateerrorevent.update_error, statusupdateerror); Appupdater.addeventlistener (Updateevent.download_start, downloadstarted); Appupdater.addeventlistener (progressevent.progress, downloadprogress); Appupdater.addeventlistener (Updateevent.download_complete, downloadcomplete); Appupdater.addeventlistener (Downloaderrorevent.download_error, downloaderror); Appupdater.addeventlistener (Errorevent.error, updatererror); Appupdater.initialize (); } Private varappversion:string; Private varbaseurl:string; Private varupateversion:string; Private vardescription:string; Private varisfirstrun:string; Private varapplicationname:string; Private varinstalledversion:string; Private functionUpdaterinitialized (event:updateevent):void { This. IsFirstRun =Event.target.isFirstRun; This. ApplicationName =Getapplicationname (); This. installedversion =getapplicationversion (); Appupdater.checknow (); } Private functiongetapplicationversion (): String {varAppxml:xml =NativeApplication.nativeApplication.applicationDescriptor; varNs:namespace =Appxml.namespace (); returnappxml.ns::version; } /** Getter method to get the name of the application, this does not a support multi-language. * Based on a method from Adobes Applicationupdaterdialogs.mxml, which are part of Adobes AIR Updater Framework * Al So based on Jens Krause blog post:http://www.websector.de/blog/2009/09/09/ custom-applicationupdaterui-for-using-air-updater-framework-in-flex-4/* * @return String name of Applicat Ion **/ Private functiongetapplicationname (): String {varapplicationname:string; varXmlns:namespace=NewNamespace ("Http://www.w3.org/XML/1998/namespace"); varAppxml:xml=NativeApplication.nativeApplication.applicationDescriptor; varNs:namespace=Appxml.namespace (); //filename is mandatory varelem:xmllist=Appxml.ns::filename; //Use name are if it exists in the application descriptor if((appxml.ns::name). Length ()! = 0) {Elem=Appxml.ns::name; } //See If element contains simple content if(Elem.hassimplecontent ()) {ApplicationName=elem.tostring (); } returnApplicationName; } Private functionStatusupdate (event:statusupdateevent):void { //Stop the event from triggering the update download/install by itselfTrace (event.tostring ()); Event.preventdefault (); if(event.available) {varalertinfo:string="Discover the new version ("+ Event.version +"), do you want to upgrade now?; varalerttitle:string="Upgrade Tips"; varalertflag:uint=alert.ok|Alert.cancel; Alert.oklabel="Yes"; Alert.cancellabel=" Great place to stay"; Alert.show (Alertinfo,alerttitle,alertflag,this,updatechoicealerthandler); }Else { This. dispatchevent (NewEvent (event.complete)); } } Private functionUpdatechoicealerthandler (event:closeevent):void{Trace ("Updatechoicealerthandler:"+event.tostring ()); if(Event.detail = =Alert.ok) {appupdater.downloadupdate (); Trace ("Alert.ok"); }Else{appupdater.cancelupdate (); This. dispatchevent (NewEvent (event.complete)); Trace ("Alert.cancel"); } } Private functionBeforeinstall (event:updateevent):void {Trace (event); } Private functionStatusupdateerror (event:statusupdateerrorevent):void{event.preventdefault (); } Private functionDownloadstarted (event:updateevent):void{trace (event); } Private functionDownloadProgress (event:progressevent):void { varNum:int = (event.bytesloaded/Event.bytestotal) *100;Trace ("Updated Software"+num+"%"); } Private functionDownloadComplete (event:updateevent):void{event.preventdefault ();//Prevent default Install } Private functionDownloaderror (event:downloaderrorevent):void{event.preventdefault (); Trace (event.text); } Private functionUpdatererror (event:errorevent):void { Trace (event.text); } protectedfunctionIsnewerversionfunction (currentversion:string, updateversion:string):Boolean { varLocal_vers:array = Currentversion.split ('. '); varRemote_vers:array = Updateversion.split ('. '); varLocal_ver:int; varRemote_ver:int; varLocal_points: Number= 0; varRemote_points: Number= 0; for(vari:int=0; I<math.max (Local_vers.length, remote_vers.length); i++) {Local_ver= Local_vers.length <= I? 0: Int (local_vers[i]); Remote_ver= Remote_vers.length <= I? 0: Int (remote_vers[i]); Local_points= local_points * 100 +Local_ver; Remote_points= remote_points * 100 +Remote_ver; } returnRemote_points >local_points; }

Air app Updates

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.