今天接手一个别人的项目,看代码看了一天,有个地方我很费解,上图
plus.runtime.appid 我寻思这是个啥?
打印输出的结果 如下
我把plus给打印了 结果如下,看不懂 很费解
文字版如下 这是给人看的东西吗??
[native code] }","11":"function() { [native code] }","12":"function() { [native
code] }","13":"function() { [native code] }","14":"function() { [native code]
}","15":"function() { [native code] }","16":"function() { [native code]
}","17":"function() { [native code] }","18":"function() { [native code]
}","19":"function() { [native code]
}"},"hooks":{}}},"documentElement":{"ref":"_documentElement","type":"document","attr":{},"style":{}},"__$automator__":false,"__$compiler__":"uni-app"},"requireModule":"function()
{ [native code] }","importScript":"function() { [native code]
}","isRegisteredModule":"function() { [native code]
}","isRegisteredComponent":"function() { [native code]
}"},"weexBridge":{"preloadReady":"function() { [native code]
}","postMessage":"function() { [native code] }","execSync":"function() { [native
code] }","getConfigInfo":"function() { [native code]
}","evalJSFiles":"function() { [native code] }","uniReady":"function() { [native
code] }","removeAllEventListeners":"function() { [native code]
}","sendNativeEvent":"function() { [native code] }","pushDebugData":"function()
{ [native code] }","exec":"function() { [native code] }","getValue":"function()
{ [native code] }","getDotData":"function() { [native code]
}","addEventListener":"function() { [native code]
}","getRedirectInfo":"function() { [native code] }","log":"function() { [native
code] }","setDefaultFontSize":"function() { [native code]
}"},"globalEvent":{"addEventListener":"function() { [native code]
}","removeAllEventListeners":"function() { [native code]
}","removeEventListener":"function() { [native code]
}"},"tools":{"__UUID__":3,"UNKNOWN":-1,"IOS":0,"ANDROID":1,"platform":1,"debug":true,"UUID":"function()
{ [native code] }","extend":"function() { [native code]
}","typeName":"function() { [native code] }","isDate":"function() { [native
code] }","isArray":"function() { [native code] }","isDebug":"function() {
[native code] }","stringify":"function() { [native code]
}","isNumber":"function() { [native code]
}","getElementOffsetInWebview"
遂开始面向百度编程 这个东西是跟app的升级更新有关 其实我现在还是没有整太明白,但是有时候不怕百度就怕不知道咋百度,所以把我遇到的问题分享给大家,希望对你有帮助
粘贴原文如下————
uni-app 整包升级/更新方案
w微凉半秋
2019.10.31 21:40:00
注意:plus.runtime.appid,plus.runtime.version, plus.runtime.openURL()
在真机环境下才有效使用 uni-app 开发,可将代码编译到iOS、Android、微信小程序等多个平台,升级时也需考虑多平台同步升级。
uni-app发布为小程序的升级模式较简单,只需将开发完的代码提交小程序后台,待审核通过后用户将自动升级 iOS/Android App
的升级需开发者自己处理,本文主要简介 App 的整包升级模式。 App
的资源热更新另见文档:http://ask.dcloud.net.cn/article/35667 接口约定
如下数据接口约定仅为示例,开发者可以自定义接口参数。 请求地址:https://www.example.com/update请求方法:GET
请求数据:
"appid": plus.runtime.appid, "version": plus.runtime.version } ``` 响应数据: ```javascript { "status":1,//升级标志,1:需要升级;0:无需升级 "note": "修复bug1;\n修复bug2;",//release notes "url": "http://www.example.com/uniapp.apk" //更新包下载地址 } ``` 客户端实现 App启动时,向服务端上报当前版本号,服务端判断是否提示升级。 在App.vue的onLaunch中,发起升级检测请求,如下: ```javascript onLaunch: function () { //#ifdef APP-PLUS var server = "https://www.example.com/update"; //检查更新地址 var req = { //升级检测数据 "appid": plus.runtime.appid, "version": plus.runtime.version }; uni.request({ url: server, data: req, success: (res) => { if (res.statusCode == 200 && res.data.status === 1) { uni.showModal({ //提醒用户更新 title: "更新提示", content: res.data.note, success: (res) => { if (res.confirm) { plus.runtime.openURL(res.data.url); } } }) } } }) //#endif } ``` 注意:App的升级检测代码必须使用条件编译,否则在微信环境由于不存在plus相关API,将会报错。 服务端实现 根据客户端上报的版本号,比对服务端最新版本号,决定是否需要升级,若需升级则返回升级信息(rease notes、更新包地址等) 开发者可以根据服务端开发语言,自己实现升级检测逻辑,如下是一个php示例代码: ```javascript header("Content-type:text/json"); $appid = $_GET["appid"]; $version = $_GET["version"]; //客户端版本号 $rsp = array("status" => 0); //默认返回值,不需要升级 if (isset($appid) && isset($version)) { if ($appid === "__UNI__123456") { //校验appid if ($version !== "1.0.1") { //这里是示例代码,真实业务上,最新版本号及relase notes可以存储在数据库或文件中 $rsp["status"] = 1; $rsp["note"] = "修复bug1;\n修复bug2;"; //release notes $rsp["url"] = "http://www.example.com/uniapp.apk"; //应用升级包下载地址 } } } echo json_encode($rsp); exit; ``` 常见问题 版本检测需要打包app,真机运行基座无法测试。因为真机运行的plus.runtime.version是固定值。 原文地址:https://ask.dcloud.net.cn/article/34972 顺便把评论也粘贴过来 Han涛_ 2楼 05.06 17:43 我这样给后端传过去,后端拿到的数据一直是null w微凉半秋 05.06 18:51 你取的前端有取到数据吗 Han涛_ 05.07 13:43 @w晚风 发现问题了,后端设置的问题,谢谢