Table of Contents
使用Appcan客户端自动更新PHP版本号(全),appcan版本号
Home php教程 php手册 使用Appcan客户端自动更新PHP版本号(全),appcan版本号

使用Appcan客户端自动更新PHP版本号(全),appcan版本号

Jun 13, 2016 am 08:56 AM
version number Automatic updates

使用Appcan客户端自动更新PHP版本号(全),appcan版本号

在项目开发过程中遇到app端自动更新,查阅了相关资料然后把Appcan客户端自动更新PHP版本号的方法整理出来,具体代码讲解如下。

服务端文件:update.php、version.php、version.xml

update.php 内容:

PHP

<&#63;php
define('CIN', true);
$oldver = $_REQUEST['ver'];//客户端传过来的版本号
$platform = $_REQUEST['platform'];//客户端的平台
$info = simplexml_load_file('version.xml');
$iphone_filename=$info->news['iphone_filename']; //iphone下载文件
$android_filename=$info->news['android_filename']; //androiad下载文件
$version=$info->news['version']; //版本号
if ($version>$oldver)
{
  switch ($platform)
  {
    case "0"://iphone
      echo "<&#63;xml version=\"1.0\" encoding=\"utf-8\"&#63;>";
      echo "<results>";
      echo "<updateFileName>i2ty</updateFileName>";//客户端名字
      echo "<updateFileUrl>itunesURL</updateFileUrl>";//返回给客户端的下载地址
      echo "<fileSize>0</fileSize>";//文件大小
      echo "<version>".$version."</version>";//版本信息
      echo "</results>";
      break;
    case "1"://android
      echo "<&#63;xml version=\"1.0\" encoding=\"utf-8\"&#63;>";
      echo "<results>";
      echo "<updateFileName>i2ty</updateFileName>";//客户端名字
      echo "<updateFileUrl>http://i2ty.com/app/".$android_filename."</updateFileUrl>";//返回给客户端的下载地址
      echo "<fileSize>0</fileSize>";//文件大小
      echo "<version>".$version."</version>";//版本信息
      echo "</results>";
      break;
  }
}
&#63;>
Copy after login

version.php 内容:

PHP

<&#63;php
define('CIN', true);
$result['vtitle']="更新";
$result['vcontent']="新版本有更新喔!~新增功能修复各种错误";
print_r(json_encode($result));
&#63;>
version.xml 内容:
PHP
<&#63;xml version="1.0" encoding="utf-8" &#63;>
<root desc="Login">
 <news version="00.00.0001" iphone_filename="i2ty.ipa"  android_filename="i2ty.apk" />
</root>
index.html 客户端:
PHP
window.uexOnload = function(type){   
    if (!type) {
      update();
    }
var flag_sdcard = 1;
var updateurl = '';//下载新apk文件地址
var filepath2 = "/sdcard/";//保存到sd卡
var fileName = '';//新版本文件名
var platform = '';//平台版本
function update()
{  
    //安卓版 ,显示下载进度 (step:7)
    uexDownloaderMgr.onStatus = function(opId, fileSize, percent, status) {
        if (status == 0) {
            // 下载中...
            Log('download percent ' + percent + '%');
            uexWindow.toast('1', '5', '正在下载'+localStorage.app_title+'新版,请稍后。进度:' + percent + '%', '');
        } else if (status == 1) {// 下载完成.
            uexWindow.closeToast();
            uexDownloaderMgr.closeDownloader('14');//关闭下载对象
            uexWidget.installApp(filepath2+fileName);// 安装下载apk文件
        } else {
            uexWindow.toast('1', '5', '下载出错,请关闭'+localStorage.app_title+'再次运行.', '');
        }
    };
    //安卓版 ,创建下载对象回调函数(step:6)
    uexDownloaderMgr.cbCreateDownloader = function(opId, dataType, data) {
        Log('uexDownloaderMgr.cbCreateDownloader data='+data);
        if (data == 0) {
            //updateurl是通过调用cbCheckUpdate回调后,放入全局变量的
            uexDownloaderMgr.download('14', updateurl, filepath2+fileName, '0');//开始下载apk文件
        } else if (data == 1) { 
            ;
        } else {
            ;
        }
    };
    //提示更新模态框按钮事件回调函数,判断用户选择更新还是取消 (step:5)
    uexWindow.cbConfirm = function(opId, dataType, data) {
        Log('uexWindow.cbConfirm ');
        //调用对话框提示函数
        if (data == 0) {
            //用户点击稍后按钮,不进行更新
        } else {
            //用户点击确定按钮,进行更新
            if (platform == 0) {
                //苹果版更新,通过浏览器加载appstore路径
                uexWidget.loadApp(updateurl,'','');
                //uexWidget.loadApp("", "", updateurl);//旧方法 已经不可以使用了。
            } else if (platform == 1) {
                //安卓版更新,通过创建下载对象进行下载                
                uexDownloaderMgr.createDownloader("14");
            } else {
                ;
            }
        }
    };
    //调用检查更新回调函数,请求成功后,弹出模态框让用户选择是否现在更新(step:4)
    uexWidget.cbCheckUpdate = function(opCode, dataType, jsonData) {        
        Log('jsonData='+jsonData);
        var obj = eval('(' + jsonData + ')');
        if (obj.result == 0) {
            // tips = "更新地址是:" + obj.url + "<br>文件名:" + obj.name + "<br>文件大小:" +
            // obj.size + "<br>版本号:" + obj.version;
            updateurl = obj.url;
            fileName = obj.name+".apk";
            getVersionContent();
            // var value = "稍后;更新";
            // var mycars = value.split(";");
            // uexWindow.confirm('', '当前有新版本,是否更新&#63;', mycars);//弹出提示框,是否确定更新
        } else if (obj.result == 1) {
            //苹果
            //alert("更新地址是:" + obj.url + "<br>文件名:" + obj.name + "<br>文件大小:" +
            //obj.size + "<br>版本号:" + obj.version)
            ;// tips = "当前版本是最新的";alert(tips);
        } else if (obj.result == 2) {            
            ;// tips = "未知错误";alert(tips);
        } else if (obj.result == 3) {            
            ;// tips = "参数错误";alert(tips);
        }
    };
    //检查是否已经存在sd卡的回调函数(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不存在,根据具体情况处理');
            } else {
                //执行检查更新
                uexWidget.checkUpdate();//根据config.xml里面配置的检查更新地址发起http请求
            }
            flag_sdcard = 1;
        } 
    };
    //获取平台版本回调函数,确定是客户端是那个平台的客户端 (step:2)
    uexWidgetOne.cbGetPlatform = function(opId, dataType, data) {
        Log('uexWidgetOne.cbGetPlatform ');
        //获取系统版本信息回调函数
        platform = data;
        Log('platform= '+platform);
        if (data == 0) {
            // 是iphone
            uexWidget.checkUpdate();// 直接调用检查更新,检查更新地址在config.xml里面有配置
        } else if (data == 1) {
            // 是android
            flag_sdcard = 0;
            uexFileMgr.isFileExistByPath('/sdcard/');//先判断是否存在sd卡,再调用checkUpdate来进行更新
        } else {
            // 是平台
        }
    };
    uexWidgetOne.getPlatform();//获取平台版本 (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","连接不上网络^_^哦","3000");
    }
    if(status==1){
    uexXmlHttpMgr.close(777);
    uexWindow.closeToast();
    if(result=="[]"){uexWindow.toast("0","5","无","2000");}
    else{
      var con=eval('(' + result + ')')
      var value = "稍后;更新";
      var mycars = value.split(";");
      uexWindow.confirm(con.vtitle, con.vcontent, mycars);//弹出提示框,是否确定更新
      }
    }
}
Copy after login

最后app 的 config.xml 文件配置更新地址填写为:

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

APP端更新提示:

弹窗内容根据 version.php 文件内容可以自定义。

以上内容就是本文讲解使用Appcan客户端自动更新PHP版本号的方法,希望对大家有所帮助。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to disable Windows Update from automatically updating drivers in win11? How to disable Windows Update from automatically updating drivers in win11? Jun 26, 2024 am 12:18 AM

When you connect any new hardware device to the system, Windows will automatically try to install the driver for it. When the system's built-in driver package cannot be recognized, it will automatically try to connect to Windows Update to search and install the driver. Windows can also automatically update device drivers through Windows Update without user interaction. Although this function seems convenient, under certain circumstances, the feature of automatically updating drivers can cause trouble for users. For example, users' video workflows such as DaVinciResolve, Adobe Premiere, etc. need to use a specific old version of Nvidia Studio driver. As a result, Windows

How to disable automatic updates in Win11 How to disable automatic updates in Win11 Dec 27, 2023 pm 12:53 PM

Many users always receive automatic updates from the system when using their computers on a daily basis, which not only slows down the computer but also causes it to become stuck. For this reason, today we bring you how to operate Win11 if you don’t want to automatically update. If automatic updates keep affecting you, Let’s see how to close it. How to prevent Windows 11 system from automatically updating 1. First, right-click "This PC" on the desktop and select "Manage". 2. In the opened "Computer Management", click "Services" → "Applications" → "Services" → "Windows update". 3. Next, double-click "Windows update", set the "Startup type" to "Disabled", click "Stop" service and confirm. 4. Click the "Recover" tab to restore the first lost

Group policy method to turn off automatic updates in win10 Group policy method to turn off automatic updates in win10 Dec 23, 2023 pm 05:07 PM

When using win10 system, we all often encounter update problems. This update is sometimes very annoying, so how can we solve this problem? This requires us to enter the local group policy to set it. How to turn off automatic updates in Win10 Group Policy: 1. Press "win+R" on the keyboard to open Run, enter "gpedit.msc" and click OK. 2. Select "Administrative Templates" - "Windows Components" and double-click to enter. 3. Then find "Windows Update" and double-click to enter. 4. Find "Configure automatic updates" on the right and double-click to open it. 5. Then check "Disabled" and click "Apply".

How to develop a feature that automatically updates a WordPress plugin How to develop a feature that automatically updates a WordPress plugin Sep 05, 2023 am 10:40 AM

How to Develop an Auto-Updating WordPress Plugin WordPress is a very popular open source content management system (CMS) with a rich plugin market to extend its functionality. To ensure that plugins are always up to date and secure, developers need to implement automatic updates. In this article, we’ll walk you through how to develop an auto-updating WordPress plugin and provide code examples to help you get started quickly. Preparation Before starting development, you need to prepare the following key steps: Create

Debian version numbers, codenames and software sources Debian version numbers, codenames and software sources Feb 20, 2024 am 09:01 AM

Debian is one of the largest distributions of Linux systems, but its version naming has always troubled me. Therefore, I sorted out the naming and relationships of various Debian versions. Version number (number) Debian version number is directly represented by numbers, such as Debian8, 9, 10, 11 and so on. Starting with Debian 6, every major distribution will add 1 to the original number. For example, Debian12 will be released in 2023. Based on the current version, small updates are represented by increasing decimals. For example, after Debian 12.0 is released, the subsequent updated versions are 12.1, 12.2, etc. The version number is relatively conventional and in line with general knowledge. Version code (nickname) In addition to the version number,

How to turn off automatic updates on Redmi 13c? How to turn off automatic updates on Redmi 13c? Mar 04, 2024 pm 09:49 PM

Today’s mobile phones are becoming more and more powerful, with more and more comprehensive functions, and also provide users with a more comfortable experience. As the latest new model released, Redmi13C also has many functions and also provides users with There are many new designs coming, so how to turn off automatic updates on Redmi 13c? Let the editor of this website briefly introduce the functions to you. If you need it, you can come and take a look. How to turn off automatic updates on Redmi 13c? 1. Open the phone settings and click My Device. 2. Click MIUI version. 3. Click on the three dots in the upper right corner. 4. Click System Update Settings. 5. Turn off the switches behind automatic downloads and smart updates. It is necessary to know about turning off automatic updates. The above is the Redmi 13

How to turn off automatic updates when downloading office 2016 - How to turn off automatic updates when downloading office 2016 How to turn off automatic updates when downloading office 2016 - How to turn off automatic updates when downloading office 2016 Mar 04, 2024 pm 04:34 PM

Many people are using office 2016 download in the office, but do you know how to turn off automatic updates in office 2016 download? Below, the editor will tell you how to turn off automatic updates in office 2016 download. Interested users can take a look below. First open a component. For example, you can open the EXCEL spreadsheet software of Office 2016. Other components are also available. Click the file menu in the upper left corner of the interface and operate as shown. Find the account option here on the left, open it, and start the operation. Click the Disable updates button in the update options. When the Office update shows that this product cannot be updated, it means that our settings are complete. When we need to update in the future, we

How does Kirin OS provide automatic update and upgrade functions? How does Kirin OS provide automatic update and upgrade functions? Aug 06, 2023 pm 05:49 PM

How does Kirin OS provide automatic update and upgrade functions? With the continuous advancement of technology and the increasing importance of operating systems, users have increasingly higher requirements for the stability, security and functions of operating systems. In order to meet the needs of users, the operating system needs to provide automatic updates and upgrades, fix vulnerabilities and add new features in a timely manner. As a domestically developed operating system, Kirin operating system is no exception. It provides automatic update and upgrade functions. In the Kirin operating system, the automatic update and upgrade functions are mainly through the software package manager and update software.

See all articles