Giter Club home page Giter Club logo

Comments (9)

vaenow avatar vaenow commented on July 2, 2024
  1. 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;
  1. 如何查看返回状态码?

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.

YoungBot avatar YoungBot commented on July 2, 2024

谢谢你的回复!我已经得到了返回状况码。
我现在又有两个问题:
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.

vaenow avatar vaenow commented on July 2, 2024
  • 如果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.

YoungBot avatar YoungBot commented on July 2, 2024

谢谢你 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.

donkeyban avatar donkeyban commented on July 2, 2024

您好
請問window.AppUpdate.checkAppUpdate(onSuccess, onFail, updateUrl);
其中updateUrl一定要是一個網路上的xml文件嗎?
可以直接傳入一個xml格式的字串嗎?
因為目前我是直接傳入字串,但是都出現405錯誤
謝謝您

from cordova-plugin-app-update.

vaenow avatar vaenow commented on July 2, 2024

@YoungBot 具体的业务逻辑还需要你去调试。 如果发现有需要改进的地方,请继续留言。 👍

@donkeyban 目前updateURL只支持文件地址 😃

from cordova-plugin-app-update.

YoungBot avatar YoungBot commented on July 2, 2024

你好VAENOW,
谢谢你之前的答复。我现在用了另一个方法规避了callback的问题。我现在想请教你,如果我想把移至后台下载这个选项按钮去除,我该怎么做?我可以简单的在plugin的java文件里面把代码注释掉还是我需要用别的方法?
谢谢!

from cordova-plugin-app-update.

vaenow avatar vaenow commented on July 2, 2024

@YoungBot 可以注释掉相关的代码就好了

from cordova-plugin-app-update.

rohananarse avatar rohananarse commented on July 2, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.