日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

hbuilder热更新

發布時間:2024/9/27 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 hbuilder热更新 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

前端代碼:

// 獲取當前應用的版本號

? var wgtVer=null; function plusReady(){// ......// 獲取本地應用資源版本號plus.runtime.getProperty(plus.runtime.appid,function(inf){wgtVer=inf.version;console.log("當前應用版本:"+wgtVer);checkUpdate();?}); } if(window.plus){plusReady(); }else{document.addEventListener('plusready',plusReady,false); }?




// 發起ajax請求檢測是否有新版本

var checkUrl="http://ptest.liby.com.cn/MessageTransfer.php?c=message&m=getupdatetwo"; function checkUpdate(){ // ? ? plus.nativeUI.showWaiting("檢測更新...");var xhr=new XMLHttpRequest();xhr.onreadystatechange=function(){switch(xhr.readyState){case 4:plus.nativeUI.closeWaiting();if(xhr.status==200){console.log("檢測更新成功:"+xhr.responseText);var newVer=xhr.responseText;newVer = JSON.parse(newVer);if(wgtVer&&newVer&&(wgtVer.substring(0,3) < newVer.versionName.substring(0,3))){if(window.confirm('檢測到更新,是否更新?')){downWgt(newVer.apk);? // 下載升級包}}else{// plus.nativeUI.alert("無新版本可更新!");}}else{console.log("檢測更新失敗!");// plus.nativeUI.alert("檢測更新失敗!");}break;default:break;}}xhr.open('GET',checkUrl);xhr.send(); }// 下載wgt文件 // var wgtUrl="http://demo.dcloud.net.cn/test/update/H5EF3C469.wgt"; function downWgt(wgtUrl){ // console.log(wgtUrl);return;plus.nativeUI.showWaiting("下載更新文件...");plus.downloader.createDownload( wgtUrl, {filename:"_doc/update/"}, function(d,status){if ( status == 200 ) {?console.log("下載更新文件成功:"+d.filename);installWgt(d.filename); // 安裝wgt包} else {console.log("下載失敗!");plus.nativeUI.alert("下載失敗!");}plus.nativeUI.closeWaiting();}).start(); }// 更新應用資源 function installWgt(path){plus.nativeUI.showWaiting("安裝更新文件...");plus.runtime.install(path,{},function(){plus.nativeUI.closeWaiting();console.log("安裝更新文件成功!");plus.nativeUI.alert("應用資源更新完成!",function(){plus.runtime.restart();});},function(e){plus.nativeUI.closeWaiting();console.log("安裝更新文件失敗["+e.code+"]:"+e.message);plus.nativeUI.alert("安裝更新文件失敗["+e.code+"]:"+e.message);if(e.code == 10){alert('請清除臨時目錄');}});}php代碼:public function getupdatetwo(){$arr = array('versionCode' => 102,'versionName' => '1.8.0','msg' => '有新版本可供更新.\n 1.界面美化 \n 2.性能優化','apk' => 'http://cloud-dev.playxs.com/static/app/H50488D36.wgt',//存放在服務器的升級資源包);echo trim(json_encode($arr));}

?

總結

以上是生活随笔為你收集整理的hbuilder热更新的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。