Why hot update

Hot update mainly refers to the bug appearing on the page after the launch of the app, which has to be packaged and launched after modification. Every time the user has to download it in the application market, which will affect the user experience. If the user is unwilling to update and keeps reminding them not to update, the bug will always exist. You can accidentally write the wrong code, and the entire team’s efforts will be wasted, which is why hot updates are important.

First you need to change the version number in manifest.json

If it was 1.0.0 then change it to say 1.0.1 or 1.1.0

Then you need to type a WGT package in HBuilderX

Go to The top > Releases > Native App- make the Mobile App resource upgrade pack

The location of the package is printed in the console

You need to make an interface with the back end, pass parameters

You can then code hot updates in the onLaunch of app.vue, and if you have other requirements, you can do so in the onLoad of other pages.

// #ifdef app.runtime.getProperty (plus.runtime.appId, Function (widgetInfo) {uni. Request ({url:' request url to write your own ', method: "POST", data: {version: Widgetinfo. version, //app version name: widgetInfo.name //app name}, success: (result) => {console.log(result) // Successful data request var data = result.data.data if (data.update && data.wgturl) {var uploadTask = uni.downloadFile({// download url: data.wgtUrl, // download WGT file success: (downloadResult) = > {/ / download successfully executed the if (downloadResult. StatusCode = = = 200) { plus.runtime.install(downloadResult.tempFilePath, { force: flase }, function() { plus.runtime.restart(); }, function(e) {}); }}}) uploadTask. OnProgressUpdate ((res) = > {/ / test conditions, cancel the upload task. If (res.progress == 100) {//res.progress uploadTask.abort(); }}); }}}); }); // #endifCopy the code

Unsupported situations

  • There are some adjustments in the SDK, such as the addition of Maps module, etc., which cannot be upgraded in this way, but must be upgraded in the whole package.
  • The same cannot be done with native add-ons. For the old non-custom component compilation pattern, this pattern has been phased out. However, it is important to note that the old non-custom component compilation mode can not be used if the nvUE file is added in the update and the previous project did not have it. Since non-custom component compilation mode does not pack weeX engine without NVUE file, native engine cannot be added dynamically. The custom component mode includes the WEEX engine by default, regardless of nvUE files in the project.

Matters needing attention

  • Conditional compilation, which only performs this upgrade logic on the App platform.
  • Appid and version information, etc. are the information of the HBuilder application during the development of the HBuilderX real machine, so you need to pack the custom base or formal package to test the upgrade function.
  • Plus.runtime.version or uni.getSystemInfo() reads the version number of the APK/IPA package instead of the version information in the manifest.json resource. So plus.runtime.getProperty() is used to get the information.
  • After the WGT resource package is successfully installed, you must run plus.runtime.restart(). Otherwise, the new content does not take effect.
  • If the native engine of the App is not upgraded, only the WGT package should be upgraded to test the compatibility of THE WGT resources and the native base. Platform will default to remind does not match the version, if the test is no problem, can be configured in the manifest ignore the prompt, see ask.dcloud.net.cn/article/356…
  • www.example.com is only used as an example. In actual applications, the address must be a real IP address or a valid domain name. Do not copy and paste the address.

About whether hot updates affect app launch

In order to prevent developers from providing illegal content to users without approval from the market, the app market is largely averse to hot updates.

But hot updates are actually very common, both in native development and across platforms.

Apple has banned Jspatch in the past, but has not cracked down on other hot updates, including Cordovar, React Native, and DCloud. Jspatch was banned because it had a serious security flaw that could be exploited by hackers, allowing third-party hackers to tamper with other apps’ data.

Notes for using hot updates:

  • Do not pop up hot update prompt during shelf review
  • Hot updates are downloaded using HTTPS to avoid being hijacked by third-party networks
  • Do not update illegal content, do not destroy the benefits of the app market through hot updates, such as iOS virtual payments to pay Apple honestly

If your app doesn’t make these mistakes, the app market doesn’t care.