Use the Appcan client to automatically update PHP versions (all) and appcan versions

Source: Internet
Author: User
Tags file url

Use the Appcan client to automatically update PHP versions (all) and appcan versions

In the process of project development, when the app is automatically updated, check the relevant information and then sort out the Appcan client's automatic PHP version update method. The specific code is described as follows.

Server files: update. php, version. php, and version. xml

Update. php content:

PHP

<? Phpdefine ('cin', true); $ oldver =$ _ REQUEST ['ver ']; // The version passed by the client $ platform =$ _ REQUEST ['platform']; // client platform $ info = simplexml_load_file ('version. xml '); $ iphone_filename = $ info-> news ['iphone _ filename']; // download the iphone File $ android_filename = $ info-> news ['android _ filename']; // download the file $ version = $ info-> news ['version'] From androiad; // version if ($ version> $ oldver) {switch ($ platform) {case "0": // iphone echo "<? Xml version = \ "1.0 \" encoding = \ "UTF-8 \"?> "; Echo" <results> "; echo" <updateFileName> i2ty </updateFileName> "; // client name echo" <updateFileUrl> itunesURL </updateFileUrl> "; // echo "<fileSize> 0 </fileSize>" returned to the client; // echo file size "<version> ". $ version. "</version>"; // version information echo "</results>"; break; case "1": // android echo "<? Xml version = \ "1.0 \" encoding = \ "UTF-8 \"?> "; Echo" <results> "; echo" <updateFileName> i2ty </updateFileName> "; // client name echo" <updateFileUrl> http://i2ty.com/app ". $ android_filename. "</updateFileUrl>"; // echo returned to the client "<fileSize> 0 </fileSize>"; // echo file size "<version> ". $ version. "</version>"; // version information echo "</results>"; break ;}}?>

Version. php content:

PHP

<? Phpdefine ('cin', true); $ result ['vtitle'] = "Update"; $ result ['vcontent'] = "updated in the new version !~ New feature to fix 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: PHPwindow. uexOnload = function (type) {if (! Type) {update ();} var flag_sdcard = 1; var updateurl = ''; // download the new apk File URL var filepath2 ="/sdcard /"; // save it to the SD card var fileName = ''; // New Version file name var platform =''; // platform version function update () {// Android version, show the download progress (step: 7) uexDownloaderMgr. onStatus = function (opId, fileSize, percent, status) {if (status = 0) {// download... log ('Download percent '+ percent +' % '); uexWindow. toast ('1', '5', 'Download' + localStorage. app_title + 'new version, please Later. Progress: '+ percent +' % ', '');} else if (status = 1) {// download complete. uexWindow. closeToast (); uexDownloaderMgr. closeDownloader ('14'); // close the uexWidget. installApp (filepath2 + fileName); // install and download the apk file} else {uexWindow. toast ('1', '5', 'Download error. Please close '+ localStorage. app_title + 'run again. ', '') ;}}; // Android version, creates the download object callback function (step: 6) uexDownloaderMgr. cbCreateDownloader = function (opId, dataType, data) {Log ('uexdownloadermgr. cbCreat EDownloader data = '+ data); if (data = 0) {// updateurl is the uexDownloaderMgr that puts the global variable after calling the cbCheckUpdate callback. download ('14', updateurl, filepath2 + fileName, '0'); // start to download the apk file} else if (data = 1 ){;} else {;}; // prompts the Event Callback Function of the update modal box button to determine whether to choose update or cancel (step: 5) uexWindow. cbConfirm = function (opId, dataType, data) {Log ('uexwindow. cbConfirm '); // The call dialog box prompts the function if (data = 0) {// the user clicks the button later and does not update} else {// the user clicks the OK button to update the function. If (platform = 0) {// apple update, load the appstore path uexWidget in the browser. loadApp (updateurl, '',''); // uexWidget. loadApp ("", "", updateurl); // the old method is no longer available.} Else if (platform = 1) {// Android version update, download uexDownloaderMgr by creating a download object. createDownloader ("14") ;}else {;}}; // call the callback function to check the update. After the request is successful, the modal box appears, asking the user to select whether to update now (step: 4) uexWidget. cbCheckUpdate = function (opCode, ype, jsonData) {Log ('jsondata = '+ jsonData); var obj = eval (' + jsonData + ')'); if (obj. result = 0) {// tips = "Update address:" + obj. url + "<br> file name:" + obj. name + "<br> file size:" + // obj. size + "<br> Version:" + Obj. version; updateurl = obj. url; fileName = obj. name + ". apk "; getVersionContent (); // var value =" later; Update "; // var mycars = value. split (";"); // uexWindow. confirm ('', 'has a new version. Is it updated? ', Mycars); // The prompt box is displayed, whether to confirm the update} else if (obj. result = 1) {// Apple // alert ("Update address:" + obj. url + "<br> file name:" + obj. name + "<br> file size:" + // obj. size + "<br> Version:" + obj. version); // tips = "the current version is the latest"; alert (tips);} else if (obj. result = 2) {; // tips = "Unknown error"; alert (tips);} else if (obj. result = 3) {; // tips = "parameter error"; alert (tips) ;}; // check whether the SD card callback function already exists (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, handle ');} else {// execute the check to update uexWidget. checkUpdate (); // according to config. check the update address configured in xml to initiate an http request} flag_sdcard = 1 ;}}; // obtain the callback function of the platform version. Check whether the client is the client of that platform (step: 2) uexWidgetOne. cbGetPlatform = function (opId, ype, data) {Log ('uexwidgetone. cbGetPlatform '); // callback function for obtaining system version information platform = data; Log ('Platform =' + platform); if (data = 0) {// iphone uexWidget. checkUpdate (); // directly call to check for updates and check that the update address is in config. the xml contains the configuration} else if (data = 1) {// android flag_sdcard = 0; uexFileMgr. isFileExistByPath ('/sdcard/'); // first judge whether an SD card exists, and then call checkUpdate for update} else {// platform}; uexWidgetOne. getPlatform (); // obtain the 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", "cannot connect to the 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); // a prompt box is displayed, whether to confirm the update }}}

Enter the configuration update address in the config. xml file of the app as follows:

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

APP update prompt:

The pop-up window content can be customized according to the version. php file content.

The above content explains how to use the Appcan client to automatically update the PHP version number.

Related Article

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.