apiCloud手动检测更新
有时候需要给用户一个自主的权利,自主检测app是否是最新版本。


如何实现?
1.点击调用接口,检测是否有更新。
默认APICloud会自动检测版本更新,用户也可以在config.xml里配置autoUpdate为false,然后使用mam模块来检测更新,mam模块还提供自定义事件功能
示例代码:
var mam = api.require('mam');
mam.checkUpdate(function( ret, err ){
if (ret) {
alert( JSON.stringify( ret ) );
} else{
alert( JSON.stringify( err ) );
}
});
返回数据:
{
status:true, //操作成功状态值
result:
{
update:true, //是否有更新
closed:true, //设备上当前版本是否被强行关闭
version:'1.0', //新版本版本号
versionDes:'', //新版本更新描述
closeTip:'', //提示用户应用版本被强行关闭时弹框的提示语
updateTip:'', //提示用户有更新时弹框的提示语
source:'', //新版本安装包的下载地址
time:'' //新版本的发布时间
}
}
2.弹出comfirm框,让用户选择是否升级
layer.confirm('有新版本啦!<br/>最新版本:'+ret.result.version+'<br/>更新描述:<br/>'+updateTip+'<br/>发布时间:'+ret.result.time,
{
title:'更新提示',
btn: ['立即更新','取消'] //按钮
}, function(){
}, function(){
});
3.执行下载操作,api中有download方法
api.download({
url: url,
savePath: 'fs://test.rar',
report: true,
cache: true,
allowResume: true
}, function(ret, err) {
if (ret.state == 1) {
//下载成功
} else {
}
});
4.执行安装installApp方法
//Android用法:
api.installApp({
appUri: 'file://xxx.apk'
});
//iOS用法:
api.installApp({
appUri: 'https://list.kuaiapp.cn/list/KuaiAppZv7.1.plist' //安装包对应plist地址
});
整合如下:
// 检查更新
function checkUpdate() {
var mam = api.require('mam');
mam.checkUpdate(function( ret, err ){
if (ret) {
if (!ret.status) {
toast('服务器繁忙,请稍后再试');
return;
}
if (ret.result.update) {
var updateTip;
updateTip = ret.result.updateTip.replace(/\r\n/g,"<BR>");
updateTip =updateTip.replace(/\n/g,"<BR>");
layer.confirm('有新版本啦!<br/>最新版本:'+ret.result.version+'<br/>更新描述:<br/>'+updateTip+'<br/>发布时间:'+ret.result.time,
{
title:'更新提示',
btn: ['立即更新','取消'] //按钮
}, function(){
if (api.systemType == "android") {
api.download({
url : ret.result.source,
report : true
}, function(retdownload, err) {
if (retdownload && 0 == retdownload.state) {/* 下载进度 */
api.toast({
msg : "正在下载应用" + retdownload.percent + "%",
duration : 2000
});
}
if (retdownload && 1 == retdownload.state) {/* 下载完成 */
var savePath = retdownload.savePath;
api.installApp({
appUri : savePath
});
}
});
}
if (api.systemType == "ios") {
api.installApp({
appUri : ret.result.source
});
}
}, function(){
});
return;
} else {
toast('当前已是最新版本');
return;
}
} else{
toast('服务器繁忙,请稍后再试');
return;
}
});
}
apiCloud手动检测更新的更多相关文章
- IOS开发中如何实现自动检测更新APP
自动检测更新实现逻辑: 先上github地址:https://github.com/wolfhous/HSUpdateApp 1,获取当前项目APP版本号 2,拿到AppStore项目版本号 3,对比 ...
- iOS 开发笔记 - 开发中如何实现自动检测更新APP
1.获取当前项目APP版本号 2.拿到AppStore项目版本号 3.对比版本号,实现更新功能 直接上代码: #import "ViewController.h" //1一定要先配 ...
- 关于window10更新之后,15.5版本虚拟机不能使用的情况:检测更新版本
1.用了四五年的虚拟机,最近居然老提示检测更新版本,嗯,我将我的虚拟机由10版本,更新到了15.5版本,这也是网友说的,然而并灭有什么乱弄.window10系统自动更新,自动更新以后虚拟机就打不开了, ...
- Nexus5如何手动OTA更新系统到4.4.3、4.4.4及常见问题回答
这里将记录一套行之有效的Nexus5手动升级方法,以帮助看见这篇文章的朋友成功将手头的Nexus5升级到4.4.4. 因为谷歌服务器的事,我的这次OTA更新起来走了很多弯路.我试过挂VPN等待系统来更 ...
- iOS 检测更新版本
获取app版本URL 数字是appID,在开发者账号app信息中可以找到 #define APP_URL @"http://itunes.apple.com/cn/lookup?id=116 ...
- apicloud 上传/更新App版本到 ios store 流程步骤
app更新 上传APP的地址: https://itunesconnect.apple.com/login 苹果开发者中心: https://developer.apple.com/ app正式包更新 ...
- IOS 通过苹果开放API检测更新
#define APPID @"1067207206" -(void)onCheckVersion { NSDictionary *infoDic = [[NSBundle mai ...
- sublime text3入门笔记以及屏蔽sublime自动升级检测更新
两个月前学习python的时候,有人推荐这个程序员最好用的编辑器,我下载了之后,发现比notepad++要好用很多,目前来说,网上成熟的版本是sublime text2简体中文版,插件也是很兼容,我用 ...
- 关闭sublime自动检测更新提示
在使用sublime text 3的时候,有自动更新的话再打开的时候总是提醒更新,这让我这个强迫症重度患者非常难受,要取消自动检查更新,点击菜单栏"Preferences"=> ...
随机推荐
- BZOJ2870 最长道路tree(并查集+LCA)
题意 (n<=50000) 题解 #include<iostream> #include<cstring> #include<cstdio> #include ...
- pandas 2 选择数据
from __future__ import print_function import pandas as pd import numpy as np np.random.seed(1) dates ...
- 【BZOJ 1257】[CQOI2007]余数之和
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] k%i=k-(k/i)i 则∑k%i = nk-∑(k/i)*i 因为k/i是整除运算. 所以会有某一段连续的i,它们的k/i的值都 ...
- mysql中的锁表语句查看方法汇总
mysql> show status like 'Table%'; +----------------------------+----------+ | Variable_name | Val ...
- SQL 字符串操作函数
SQL 字符串操作函数 学习了: https://www.cnblogs.com/wangzhe688/p/6046654.html 一.字符转换函数 1.ASCII() 返回字符表达式最左端字符的A ...
- Thinking in States
Thinking in States Niclas Nilsson PEOPLE IN THE REAL WORLD HAVE A WEIRD RELATIONSHIP WITH STATE. Thi ...
- Experience Design for Sexable Forum
Mars March 16, 2015
- Mysql信息数据库:Information_schema
1. Information_schema information_schema是mysql的信息数据库. 通过该库能够查看mysql以下的数据库,表.权限等信息. 在数据库中会默认生成这个库.inf ...
- RISC设计原则及基本技术
CISC的特点: 指令系统庞大,指令功能复杂,指令寻址方式多,指令格式多 绝大多数指令须要多个机器周期完毕 各种指令都能够訪问存储器 採用微程序控制 有专用寄存器,少量 难以用优化编译技术生成高效的目 ...
- Orientdb基本操作
https://blog.csdn.net/clj198606061111/article/details/82314459