APICloud (11): Version update

APICloud's official website has a very clear, comprehensive and well-understood version of the version update module. The link is as follows:

http://docs.apicloud.com/Dev-Guide/version_update

 

I am here mainly to record some of the problems I encountered in the process of using it and how to deal with it.

 

1. Use automatic update :

1、config.xml 中配置: <preference name="autoUpdate" value="true" />

2. Log in to the APICloud official website, enter the console, find the "Version" node under Application Services, and click to enter the version management interface.

 

3. Click "Update APP Version", select the version and fill in the update address, update the remarks, and finally click the "Update" button.

Version: It is used to remind the update. If the version of the APP is higher than the current version, it will be said that a higher version has been installed. If it is lower, the update will be reminded.

Address: Update the address on the cloud compilation page, click on the compilation record, and click the view address icon to obtain it. Setting the address is to facilitate downloading the latest version from the specified address when updating the version.

Note: It is mainly used to fill in what changes have been made in the current version, which will be displayed in the pop-up box prompting the update.

(Note: The version information filled in has the function of deleting and closing. If you don’t want to use this version, it is best to close it. Deletion will easily lead to confusion in the version. I have deleted it several times and the version is in chaos. question)

 

4. Open the APP on your mobile phone to receive the push of the new version. However, this push will only remind you when the APP is opened, and not at other times, like WeChat updates.

(For more details, you can see the official website. There are pictures and the truth. I will record them here.)

 

2. Manual update:

Like the settings in WeChat: if the current version has been updated, there will be a red "new", click to enter the updated page.

I imitate this function here: if there is an update, the red "new" will be displayed, and a pop-up box like "automatic update" will pop up when you click to update it. If there is no update, the word "new" is not displayed, and clicking has no effect.

The page code is as follows:

<a class="weui-cell weui-cell_access" href="javascript:void(0);" onclick="checkUpdate();">
          <div class="weui-cell__hd"><img src="images/gx.png"></div>
          <div class="weui-cell__bd" style=""><p>版本更新</p></div>
           <div class="weui-new" id="remind">NEW</div>
          <div class="weui-code" id="versionID"></div>
          <div class="weui-cell__ft"></div>
</a>

JS handles it as follows:

apiready=function(){	
	/ / Determine whether there is a new version, if there is, let the word new display
	var I have = api.require ('I have');
	mam.checkUpdate (function (ret, err) {
		if (ret) {
			var result = ret.result;
			if (result.update == true && result.closed == false) {//Indicate that there is an update
				//Display update text prompting update
				$("#remind").show();
			}
		}
	});
}

//Trigger this event when "Version Update" is clicked
function checkUpdate() {
//First determine whether there is a prompt to update, if there is no prompt, there is no update
if(!($("#remind").is(":visible"))){
	api.alert({
        msg : "No update yet"
    });
    return false;
}
var I have = api.require ('I have');
mam.checkUpdate (function (ret, err) {
    if (ret) {
        var result = ret.result;
        if (result.update == true && result.closed == false) {
            var str = 'latest version:' + result.version + '\nupdate description\n:' + result.updateTip + '\nrelease time:' + result.time;
            api.confirm({
                title : 'Update Tips',
                msg : str,
                buttons : ['Cancel','Update now']
            }, function (ret, err) {
                if (ret.buttonIndex == 2) {
                    if (api.systemType == "android") {
                        api.download({
                            url : result.source,
                            report : true
                        }, function (ret, err) {
                            if (ret && 0 == ret.state) {/* download progress*/
                                api.toast({
                                    msg : "Downloading app" + ret.percent + "%",
                                    duration : 2000
                                });
                            }
                            if (ret && 1 == ret.state) {/* download complete*/
                                var savePath = ret.savePath;
                                api.installApp({
                                    appUri: savePath
                                });
                            }
                        });
                    }
                    if (api.systemType == "ios") {
                        api.installApp({
                            appUri: result.source
                        });
                    }
                }
            });
        } else {
            api.alert({
                msg : "No update yet"
            });
            }
        } else {
            api.alert({
                msg : err.msg
            });
        }
    });
}

Remember to add the mam module.

good luck!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326527021&siteId=291194637