Comments (9)
- checkAppUpdate 的返回状态码可以在这个文件查询 Constants.java
/* 下载中 */
int DOWNLOAD = 1;
/* 下载结束 */
int DOWNLOAD_FINISH = 2;
/* 点击开始下载按钮*/
int DOWNLOAD_CLICK_START = 3;
/**
* 对比版本号
*/
int VERSION_COMPARE_START = 200; //private 开始对比版本号; start to compare version
int VERSION_NEED_UPDATE = 201; //检查到需要更新; need update
int VERSION_UP_TO_UPDATE = 202; //软件是不需要更新;version up to date
int VERSION_UPDATING = 203; //软件正在更新;version is updating
/**
* 版本解析错误
*/
int VERSION_RESOLVE_FAIL = 301; //版本文件解析错误 version-xml file resolve fail
int VERSION_COMPARE_FAIL = 302; //版本文件对比错误 version-xml file compare fail
/**
* 网络错误
*/
int REMOTE_FILE_NOT_FOUND = 404;
int NETWORK_ERROR = 405;
/**
* 没有相应的方法
*/
int NO_SUCH_METHOD = 501;
/**
* 未知错误
*/
int UNKNOWN_ERROR = 901;
- 如何查看返回状态码?
https://github.com/vaenow/cordova-plugin-app-update-demo/blob/master/www/js/index.js#L44
function onSuccess() {
console.log('success', JSON.stringify(arguments), arguments);
// success {"0":{"code":201,"msg":"success, need date."}}
}
from cordova-plugin-app-update.
谢谢你的回复!我已经得到了返回状况码。
我现在又有两个问题:
1.我在OnSuccess function 里面用
arguments[0].code 来的到返回状况吗。但是如果arguments[0]不存在,那么程序就崩溃了。能否保证这个arguments[0]必定存在?或者会不会存在arguments[1]或者arguments[2]?
2.我使用了另一个plugin来做target file update,如果有新的目标文件更新,他会在下载结束后
refresh 整个程序。但是这样做的话window.AppUpdate.checkAppUpdate(onSuccess, onFail, updateUrl); 里面的callback不会运行。我得到的log是
Attempted to send a second callback for ID: AppUpdate1451543198 Result was: {"code":202,"msg":"success, up to date."},
成功和失败两个callback里的代码都不会运行。
我google了一下这个问题,有人说添加代码
PluginResult result = new PluginResult(PluginResult.Status.OK, "YOUR_MESSAGE");
// PluginResult result = new PluginResult(PluginResult.Status.ERROR, "YOUR_ERROR_MESSAGE");
result.setKeepCallback(true);
callbackContext.sendPluginResult(result);
用这个方法使callback能被多次调用,但是我不知道在哪里添加这个。我感觉可能这个是要更改plugin的代码。
有什么好的解决方法吗?
谢谢!
from cordova-plugin-app-update.
- 如果arguments[0]不存在,那么程序就崩溃了
这种情况你可以试试
console.log(arguments[0] && arguments[0].code);
- 下载结束后refresh 整个程序
你可以尝试把refresh移到onSuccess和onFail里面,保证检查更新的流程结束后,再执行refresh
window.AppUpdate.checkAppUpdate(onSuccess, onFail, updateUrl);
function onSuccess(){ refresh() }
function onFail(){ refresh() }
function refresh(){
//refresh app
}
from cordova-plugin-app-update.
谢谢你 VAENOW,
我现在的代码是这样的:
function checkAppVersionUpdate() {
var updateUrl = "http://192.168.0.11/version.xml";
var versionCode = AppVersion.build;
console.log('version code: ' + versionCode);
window.AppUpdate.checkAppUpdate(onSuccess, onFail, updateUrl);
var me = this;
function onFail() {
console.log('check file update');
checkAppFileUpdate();
}
function onSuccess() {
if (arguments[0].code == 202)
{
console.log('no need update');
checkAppFileUpdate();
}
else
{
console.log('apk needs update');
}
}
}
function checkAppFileUpdate(){
var fs = new CordovaPromiseFS({
Promise: Promise
});
// Initialize a CordovaAppLoader
var loader = new CordovaAppLoader({
fs: fs,
serverRoot: 'http://192.168.0.11/manifest/www/',
localRoot: 'app',
cacheBuster: true, // make sure we're not downloading cached files.
checkTimeout: 10000 // timeout for the "check" function - when you loose internet connection
});
var needToUpdate = loader.check().then(function(){
console.log('check finished');
return loader.download();
//download to this location cdvfile://localhost/persistent/app
}).then(function(){
console.log('download finished');
return loader.update().then(parseManifestFile());
},
function(err){
console.error('UPDATE ERROR:'+ err);
parseManifestFile();
});
}
我是在checkAPKUpdate 这个函数里面当OnFail或者OnSuccess无需更新时候调用的checkAppFileUpdate函数。
在checkFileUpdate里面的 loader.update()函数是做refresh。但是这样的结果就是我之前发的那段log。然后就没法重新继续运行程序。因为没法调用OnSuccess或者OnFail。
from cordova-plugin-app-update.
您好
請問window.AppUpdate.checkAppUpdate(onSuccess, onFail, updateUrl);
其中updateUrl一定要是一個網路上的xml文件嗎?
可以直接傳入一個xml格式的字串嗎?
因為目前我是直接傳入字串,但是都出現405錯誤
謝謝您
from cordova-plugin-app-update.
@YoungBot 具体的业务逻辑还需要你去调试。 如果发现有需要改进的地方,请继续留言。 👍
@donkeyban 目前updateURL只支持文件地址 😃
from cordova-plugin-app-update.
你好VAENOW,
谢谢你之前的答复。我现在用了另一个方法规避了callback的问题。我现在想请教你,如果我想把移至后台下载这个选项按钮去除,我该怎么做?我可以简单的在plugin的java文件里面把代码注释掉还是我需要用别的方法?
谢谢!
from cordova-plugin-app-update.
@YoungBot 可以注释掉相关的代码就好了
from cordova-plugin-app-update.
i guys im still stuck here using ionic 3 how do i use this check condition of 202 (right now app keeps on updating itself even if i update)
from cordova-plugin-app-update.
Related Issues (20)
- my app continuosly ask for "upadate available even though is updated once in ionic 3" HOT 5
- Download Bar doesn't fill up for when downloading APK HOT 4
- CheckAppUpdate.java uses or overrides a deprecated API.
- There was a problem while parsing the package
- App Not installing automatically in android 9 HOT 8
- Download Again / Install Manually when run with the Kiosk cordova plugin HOT 4
- App crashed after download HOT 4
- Provide full api expose
- Receiving only one message from plugin
- APK Update
- Implementation with ionic-stencil
- I don't think the plugin still has active maintainers. Here's an alternative. HOT 3
- When I open the application, I got an error in console that says: HOT 2
- Don't use this plugin! HOT 10
- This plugin is a voilation against google policies, do not install this plugin HOT 2
- Does this plugin support android10? HOT 2
- Application crash while trying to update (null.appupdate.provider)
- Do you possibly support capacitor?
- FileNotFoundException
- BSF Cordova Ecosystem Crowdfunding Plan
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cordova-plugin-app-update.