About appcan automatic upgrade function

Our current app in the UAT environment is made with appcan and html5. Many friends are asking how to upgrade the UAT app.

We will create several variables version in zy_control.js to represent the version number of the current app (Note: Because zy_control contains some initialization code for appcan, basically every page needs to import this js)

Every time we open the app, we will call appcan widgetOne on the welcome interface to get the platform and determine whether the current phone is IOS or Android


uexWidgetOne.getPlatform();//获取平台版本 (step:1)    
            uexWidgetOne.cbGetPlatform = function(opId, dataType, data)
            {
                var update = 0;
                if (data == 1)
                {
                    update = 1;
                } else
                {
                    //我是IOS
                    update = 2;
                }
                setstorage("sysos",update);//把当前的手机型号存入缓存
                $.ajax({
                    type: 'GET',
                    url: ApIp + "/ManagerDemo/app/update.do?type=" + update,
                    dataType: 'json',
                    timeout: 20000,
                    error: function(){
                        msgPrompt(getLang("wlanError"))
                    },
                    success: function(data){
                        console.log(data)
                        if (data.msg == 10000)
                        {
                            return;
                        }
                        updateUrl = data.appUrl;
                        setstorage('updateUrl', updateUrl);
                       setstorage("remoteVersion", data.version);//
                    }
                });
            };
Then initiate a request to the background to get the latest version number according to the incoming type to get the latest version number and then get the version number and store it in the cache



setstorage("remoteVersion", data.version);//    

When the user clicks the function, the download operation is performed according to the inconsistency between the current version number and the remote version number. IOS must jump to the URL for installation.

checkLogin:function (){
				
			var url=getstorage("updateUrl");
			if (menu.remoteVersion != null ) {
				if (menu.remoteVersion != version) {

					uexWindow.cbConfirm = function(){
						switch(index_content.os){
							case 1:
								beihai365_app_update();
								break;
							case 2:
								 uexWidget.loadApp(url,null,null);
						}
					};
					uexWindow.confirm(getLang("sureMsg"), getLang("suerToUpdate"), [getLang("sure"), getLang("nosure")]);
					return false;
				}
			}
            return menu.judgeSessionId();
        }
function beihai365_app_update(){
    var flag_sdcard = 1;
    var fileName = 'AppPer.apk';//新版本文件名
    var updateurl = getstorage("updateUrl")+fileName;//下载新apk文件地址
    var filepath2 = "/sdcard/";//保存到sd卡
    var platform1 = '';//平台版本
    //var update_msg = "当前有新版本,是否更新?";  //提示文字
    
      //安卓版 ,显示下载进度 (step:7)
    uexDownloaderMgr.onStatus = function(opId, fileSize, percent, status) {
            if (status == 0) {
                    // 下载中...
                    //alert('download percent ' + percent + '%');
                    uexWindow.toast('1', '5', '下载进度:' + percent + '%', '');
            } else if (status == 1) {// 下载完成.
                    uexWindow.closeToast();
                    uexDownloaderMgr.closeDownloader('14');//关闭下载对象
                    //localStorage.clear(); 
                    //alert(filepath2+fileName);
                    uexWidget.installApp(filepath2+fileName);// 安装下载apk文件
            } else {
                     uexDownloaderMgr.closeDownloader('14');//关闭下载对象
                    //uexWindow.toast('1', '5', '请确保SD卡可正常使用.', '');
            }
    };
    //安卓版 ,创建下载对象回调函数(step:6)
    uexDownloaderMgr.cbCreateDownloader = function(opId, dataType, data) {
            //alert('uexDownloaderMgr.cbCreateDownloader data='+data);
            if (data == 0) {
                    //updateurl是通过调用cbCheckUpdate回调后,放入全局变量的
    
                    uexDownloaderMgr.download('14', updateurl, filepath2+fileName, '0');//开始下载apk文件
            } else if (data == 1) {
                    ;
            } else {
                    ;
 }
    };
    
   
    
    //检查是否已经存在sd卡的回调函数(step:3)
    uexFileMgr.cbIsFileExistByPath = function(opCode, dataType, data) {
            //alert('uexFileMgr.cbIsFileExistByPath flag_sdcard='+flag_sdcard+' , data='+data);
            if (flag_sdcard == 0) {
                    if (data == 0) {
                        scscms_alert(getLang("SDCard"), getLang("sure"));
                        //    alert('请检查手机的sd卡是否正常');
                    } else {
                         if (platform1 == 1) {
                            //安卓版更新,通过创建下载对象进行下载
                            uexDownloaderMgr.createDownloader("14");
                        }else if(platform1 == 0){
                            //苹果更新
//                            uexWidget.loadApp("", "", updateurl);
                        }
                    }
            } 
    };
    //获取平台版本回调函数,确定是客户端是那个平台的客户端 (step:2)
    uexWidgetOne.cbGetPlatform = function(opId, dataType, data) {
            //alert('b');
            //获取系统版本信息回调函数
            platform1 = data;
            //alert(platform1);
            console.log(platform1);
            if (data == 1) {
                    // 是android
                    flag_sdcard = 0;
                    uexFileMgr.isFileExistByPath('/sdcard/');//先判断是否存在sd卡,再调用checkUpdate来进行更新
            }else if(data == 0){
                //alert("我是IOS");
                //uexWidget.checkUpdate();
            }
    };
    uexWidgetOne.getPlatform();//获取平台版本 (step:1)    
}
    备注:appcan 以前确实不稳定 但是现在目前版本还是非常稳定。非常感谢appcan对我们技术的support,目前我们的app快超过千人使用 
升级功能比较稳定。



{{o.name}}
{{m.name}}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324213877&siteId=291194637