Automatically update PHP version number (full) _php instance with Appcan client

Source: Internet
Author: User
Tags eval http request php define

In the project development process encountered app-side Automatic Updates, check the relevant data and then the Appcan client automatically update the PHP version number of methods to organize, the specific code explained below.

Server-side files: update.php, version.php, Version.xml

update.php content:

Php

<?php define (' CIN ', true); $oldver = $_request[' ver '];//client-side version number $platform = $_request[' platform '];//client Platform $info = Simplexml_load_file ('
Version.xml '); $iphone _filename= $info->news[' iphone_filename ']; iphone download file $android _filename= $info->news[' android_filename ']; Androiad Download File $version = $info->news[' version ']; Version number if ($version > $oldver) {switch ($platform) {case "0"://iphone echo "<?xml version=\" 1.0\ "encod
      Ing=\ "utf-8\"?> ";
      echo "<results>"; echo "<updateFileName>i2ty</updateFileName>";//Client name echo "<updatefileurl>itunesurl</ Updatefileurl> ";//Return to the client's download address echo" <fileSize>0</fileSize> ";//File size echo" <version> ". $vers Ion. "
      </version> "//Version information echo" </results> ";
    Break
      Case "1"://android echo "<?xml version=\" 1.0\ "encoding=\" utf-8\ "?>";
      echo "<results>"; echo "<updateFileName>i2ty</updateFileName>";//Client nameThe word echo "<updatefileurl>http://i2ty.com/app/". $android _filename. " </updateFileUrl>//Return to the client's download address echo "<fileSize>0</fileSize>";//File size echo "<version>". $version. "
      </version> "//Version information echo" </results> ";
  Break
 }}?>

version.php content:

Php

<?php define (' CIN ', true);
$result [' vtitle ']= ' update '; The new version of the $result [' vcontent ']=] is updated Oh!
~ new features to repair various errors "; Print_r (Json_encode ($result))?> version.xml content: PHP <?xml version= "1.0" encoding= "Utf-8"?> <root "desc="
Login "> <news version=" 00.00.0001 "iphone_filename=" I2ty.ipa "android_filename=" i2ty.apk "/> </root>
    Index.html client: PHP window.uexonload = function (type) {if (!type) {update ();
} var flag_sdcard = 1; var updateurl = ';//download new apk file address var filepath2 = "/sdcard/";//Save to SD card var filename = ';//new version filename var platform = '//platform version Fu 
        Nction Update () {//Android version, show download Progress (step:7) Uexdownloadermgr.onstatus = function (Opid, fileSize, percent, status) {
            if (status = = 0) {//download ...
            Log (' download percent ' + percent + '% '); Uexwindow.toast (' 1 ', ' 5 ', ' Downloading ' +localstorage.app_title+ ' new edition, please later.)
        Progress: ' + percent + '% ', ');
            else if (status = = 1) {//download complete.
            Uexwindow.closetoast (); UexdownLoadermgr.closedownloader (' 14 ');//Close Download Object Uexwidget.installapp (filepath2+filename);//install download APK file} else
        {uexwindow.toast (' 1 ', ' 5 ', ' download error, please close ' +localstorage.app_title+ ' run again. ')
    }
    }; Android version, create download object callback function (step:6) Uexdownloadermgr.cbcreatedownloader = function (Opid, dataType, data) {Log (' uexdownl
        Oadermgr.cbcreatedownloader data= ' +data); if (data = 0) {//updateurl is the uexdownloadermgr.download of the global variable after invoking the cbcheckupdate callback, Updateur
        L, Filepath2+filename, ' 0 ')//start downloading APK file} else if (data = = 1) {;
        else {;
    }
    }; Prompts to update the Modal Box button event callback function to determine whether the user chooses to update or cancel (step:5) uexwindow.cbconfirm = function (Opid, dataType, data) {Log (' Uexwindow.
        Cbconfirm ');
            Call dialog box prompt function if (data = = 0) {//user Click later button, do not update} else {//user click OK button to update
      if (platform = = 0) {//Apple update, upload app path via browser          Uexwidget.loadapp (UpdateUrl, ', ');
            Uexwidget.loadapp ("", "", updateurl);/The old method is no longer available. else if (platform = 1) {//android update, download by creating download Object Uexdownloadermgr.createdo
            Wnloader ("14");
            else {;
    }
        }
    };        
        Call Check the update callback function, after the request succeeds, the pop-up modal box lets the user choose whether to update Now (step:4) uexwidget.cbcheckupdate = function (OpCode, DataType, Jsondata) {
        Log (' jsondata= ' +jsondata);
        var obj = eval (' + jsondata + ') ');
            if (Obj.result = 0) {//Tips = "Update address is:" + obj.url + <br> filename: "+ obj.name +" <br> File size: "+
            Obj.size + "<br> Version No.:" + obj.version;
            UpdateUrl = Obj.url;
            FileName = obj.name+ ". apk";
            Getversioncontent ();
            var value = "later; update";
            var mycars = Value.split (";"); Uexwindow.confirm (', ' Currently there is a new version, whether update? ', mycars);/pop-up prompt box, confirm update} ELSE if (Obj.result = 1) {//Apple//alert ("Update address is:" + obj.url + "<br> filename:" + obj.name + "<br
        > File Size: "+//obj.size +" <br> version number: "+ obj.version";//Tips = "Current version is up to date"; alert (tips);
        else if (Obj.result = 2) {;/tips = "Unknown error"; alert (tips);
        else if (Obj.result = 3) {;/tips = "parameter error"; alert (tips);
    }
    }; Check to see if the SD card's callback function (step:3) Uexfilemgr.cbisfileexistbypath = function (OpCode, dataType, data) {Log (' Uexfilemgr
        . Cbisfileexistbypath flag_sdcard= ' +flag_sdcard+ ', Data= ' +data);
            if (Flag_sdcard = = 0) {if (data = = 0) {Log (' sdcard does not exist, handled according to case ');
            else {//perform check update uexwidget.checkupdate ()//initiate HTTP request according to the check update address configured in Config.xml
        Flag_sdcard = 1;
    } 
    }; Gets the platform version callback function to determine whether the client is the client of that platform (step:2) Uexwidgetone.cbgetplatform = FunctioN (opid, DataType, data) {Log (' uexwidgetone.cbgetplatform ');
        Gets the system version information callback function platform = data;
        Log (' platform= ' +platform); if (data = = 0) {//Is the iphone uexwidget.checkupdate ()//Direct call check Update, check update address config.xml inside config} E
            LSE if (data = 1) {//is android Flag_sdcard = 0;
    Uexfilemgr.isfileexistbypath ('/sdcard/');/first determine if there is an SD card, then call checkupdate to update} else {//IS platform}
    };
    Uexwidgetone.getplatform ()//Get Platform Version (step:1)} function Log (s) {uexlog.sendlog (s);} function getversioncontent () {
    var url = web_url+ "version.php";
    Uexxmlhttpmgr.ondata = getvsuccess;
    Uexxmlhttpmgr.open (777, "get", url, ""); 
Uexxmlhttpmgr.send (777);
    function Getvsuccess (opid,status,result) {if (status = 1) {Uexwindow.toast ("0", "5", "Not connected to network ^_^ Oh", "3000");
    } if (status==1) {uexxmlhttpmgr.close (777);
    Uexwindow.closetoast (); if (result== "[]") {UEXWIndow.toast ("0", "5", "None", "2000");}
      else{var con=eval (' + result + ') ') var value = "later; update";
      var mycars = Value.split (";");
 Uexwindow.confirm (Con.vtitle, con.vcontent, mycars);/pop-up prompt box, confirm update}}}

The last app's Config.xml file configuration update address is completed as:

http://www.i2ty.com/update.php

App Side Update tips:

The window contents can be customized according to the version.php file contents.

The above content is this article explains uses the Appcan client automatically to update the PHP version number the method, hoped has the help to everybody.

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.