HBuilder打包成apk之后,如何让版本检测自动更新
var btn = [“确定升级”, “取消”];
//获取app系统更新[是否手动点击获取更新]
function appUpdate(ismanual) { console.log('appUpdate'); mui.plusReady(function () { plus.runtime.getProperty(plus.runtime.appid, function (inf) { ver = inf.version; console.log('ver:' + ver); var url = config.GetAppVersion; var client; var ua = navigator.userAgent.toLowerCase(); if (/iphone|ipad|ipod/.test(ua)) { //苹果手机 mui.ajax({ type: "get", dataType: 'json', url: "https://itunes.apple.com/lookup?id=1318127518",//获取当前上架APPStore版本信息 data: { id: 131812xxxx //APP唯一标识ID }, contentType: 'application/x-www-form-urlencoded;charset=UTF-8', success: function (data) { console.log('data:' + JSON.stringify(data)); var resultCount = data.resultCount; for (var i = 0; i < resultCount; i++) { var normItem = data.results[i].version; console.log('normItem:' + normItem) if (normItem > ver) { var _msg = "发现新版本:V" + normItem; //plus.nativeUI.alert("发现新版本:V" + normItem); mui.confirm(_msg, '升级确认', btn, function (e) { if (e.index == 0) { //执行升级操作 document.location.href = 'https://itunes.apple.com/cn/app/san-gu-hui/id131812xxxx?mt=8'; //上新APPStore下载地址 } }); return; } } if (ismanual) { mui.toast('当前版本号已是最新'); } return; } }); } else if (/android/.test(ua)) { mui.ajax(url, { data: { apkVersion: ver, }, dataType: 'json', type: 'get', timeout: 10000, success: function (data) { //console.log('data:'+JSON.stringify(data)) if (data.StatusCode = 200 && data.Data > ver) { //mui.toast("发现新版本:V" + data.Data);//获取远程数据库中上新andriod版本号 var _msg="发现新版本:V" + data.Data; mui.confirm(_msg, '升级确认', btn, function (e) { if (e.index == 0) { //执行升级操作 plus.nativeUI.toast("正在准备环境,请稍后!"); var dtask = plus.downloader.createDownload(config.apkUrl, {}, function (d, status) { if (status == 200) { var path = d.filename;//下载apk plus.runtime.install(path); // 自动安装apk文件 } else { plus.nativeUI.alert('版本更新失败:' + status); } }); dtask.start(); } }); } else { console.log('当前版本号已是最新'); if (ismanual) { mui.toast('当前版本号已是最新'); } return; } }, error: function (xhr, type, errerThrown) { if (ismanual) { mui.toast('网络异常,请稍候再试'); } } }); } }); }); }
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
感谢分享
我们的ios应用是发布在苹果应用商店的,而android应用则直接部署在我们自己的服务器上面(如IIS服务器),因为android的应用市场是在太多了,那样的话每次升级版本都是一件非常麻烦的事情,当你每发布一个版本,你不得不去所有的android应用市场去提交更新。
需要注意的是:采用手动更新和自动更新调用此方法,要传入不同的参数,因为自动更新的话,如果系统检测到当前已经是最新版本,那么将不会在客户端进行展示,而手动更新的话如果已经是最新版本,那么是需要提示客户的。
自动更新调用:appUpdate();//检测app更新
手动更新调用:appUpdate(true);//检测app更新
不过我本人使用的时候,精简了一些,因为他要调取plus对象
var first = null; document.addEventListener('plusready', function() { var webview = plus.webview.currentWebview(); plus.key.addEventListener('backbutton', function() { webview.canBack(function(e) { if(e.canBack) { webview.back(); } else { if(!first){ first = new Date().getTime(); mui.toast('再按一次退出应用'); setTimeout(function(){ first = null; },1000); }else{ if(new Date().getTime()-first<1000){ plus.runtime.quit(); } } } }) }); var btn = ["确定升级", "取消"]; plus.runtime.getProperty(plus.runtime.appid, function (inf) { ver = inf.version; $.ajax({ url:"http://218.4.57.4:19011/version", success: function (data) { if (data.result.version != ver) { var _msg="发现新版本:V" + data.result.version; mui.confirm(_msg, '升级确认', btn, function (e) { if (e.index == 0) { //执行升级操作 plus.nativeUI.toast("正在准备环境,请稍后!"); var dtask = plus.downloader.createDownload('http://218.4.57.4:19011/app/xieguan.apk', { }, function (d, status) { if (status == 200) { var path = d.filename;//下载apk plus.runtime.install(path); // 自动安装apk文件 } else { plus.nativeUI.alert('版本更新失败:' + status); } }); dtask.start(); } }); } else { console.log('当前版本号已是最新'); if (ismanual) { mui.toast('当前版本号已是最新'); } return; } }, error: function (xhr, type, errerThrown) { if (ismanual) { mui.toast('网络异常,请稍候再试'); } } }); }); });
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
还有一篇大佬差不多的文章的,也可以看看http://www.cnblogs.com/jiekzou/p/8204469.html
原文发布时间:2018-6-19
原文作者:没有名字的昵称
本文来源掘金如需转载请紧急联系作者
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
retrofit网络请求入门(多实例讲解)
之前就想抽空写一篇关于retrofit的博客,今天终于有空啦= =,话不多说。上博。 一.相关资料: Github:http://github.com/square/retrofit 官网文档:http://square.github.io/retrofit/ 相关博客:Retrofit2.0通俗易懂的学习姿势,Retrofit2.0 + OkHttp3 + Gson + RxJava 这是一份很详细的 Retrofit 2.0 使用教程(含实例讲解) 二.:模拟实现的请求以及retrofit实现步骤 本次主要使用retrofit模拟实现 1.正常get请求 2.拼接get请求(单个参数) 3.拼接get请求(多个参数) 4.get占位符请求 5.post请求 概览.JPG retrofit实现步骤: 步骤1:添加Retrofit库的依赖 步骤2:创建 接收服务器返回数据 的类 步骤3:创建 用于描述网络请求 的接口 步骤4:创建 Retrofit 实例 步骤5:创建 网络请求接口实例 并 配置网络请求参数 步骤6:发送网络请求(异步 / 同步) 步骤7: 处理服务器返回的数据 步骤讲...
- 下一篇
iOS教程 如何免费使用SMSSDK
一、注册应用获取appKey 和 appSecret(1)到Mob官网注册成为Mob开发者;(2)到应用管理后台新建应用。二、 集成SMSSDK(1)cocoapods集成方式通过 CocoaPods进行安装,只需在 Podfile文件中添加: pod 'mob_smssdk' 添加之后执行 pod install / pod update 命令即可。(2)手动集成方式 获取SMSSDK:点击链接下载最新版SDK,解压后得到以下文件结构: 导入SDK:将下图中红色框标记的文件夹(包含MOBFoundation.framework 和 SMS_SDK.framework)拖入到工程中 确认勾选,点击finish完成导入 添加依赖库:SDK所需依赖库列表: 必要:libz.dyliblibicucore.dylibMessageUI.frameworkJavaScriptCore.frameworklibstdc++.dylib注意:在XCode7上面运行报错的话,还需要增加这几个依赖库SystemConfiguration.frameworkCoreTelephony.framework...
相关文章
文章评论
共有0条评论来说两句吧...