[Development] uniapp uniapp online resource upgrade / hot update

Note: for a front end hot update code resource. If it is the whole package upgrade, see the document https://ask.dcloud.net.cn/article/34972

HBuilderX 1.6.5 onwards, uni-app supports the generation of App resource upgrade package.

App generates a resource upgrade package

Revision number

First, update the version number in manifest.json.
For example, before is 1.0.0, the new version should be 1.0.1 or 1.1.0 so.

issued

Then, in HBuilderX generate upgrade package (wgt).
Menu -> Release -> Native App App- create a mobile resource upgrade package

Generating the upgrade package will tell the end position in the console output.

Installation Resource upgrade package

Upgrade requires the server application with the completion of the client, a local test procedure below to illustrate the operation of:

Storage resources

The% appid% .wgt static files stored in the directory server, that http://www.example.com/static/UNI832D722.wgt .

The client detects upgrade

In the onLaunch detecting App.vue upgrade code is as follows:

// #ifdef APP-PLUS  
plus.runtime.getProperty(plus.runtime.appid, function(widgetInfo) {  
   uni.request({  
       url: 'http://www.example.com/update/',  
       data: {  
           version: widgetInfo.version,  
           name: widgetInfo.name  
       },  
       success: (result) => {  
           var data = result.data;  
           if (data.update && data.wgtUrl) {  
               uni.downloadFile({  
                   url: data.wgtUrl,  
                   success: (downloadResult) => {  
                       if (downloadResult.statusCode === 200) {  
                           plus.runtime.install(downloadResult.tempFilePath, {  
                               force: false  
                           }, function() {  
                               console.log('install success...');  
                               plus.runtime.restart();  
                           }, function(e) {  
                               console.error('install fail...');  
                           });  
                       }  
                   }  
               });  
           }  
       }  
   });  
});  
// #endif  

Without support

  • SDK adjust portion, such as added Maps module can not be upgraded in this way, the entire package must be upgraded by means of.
  • If it is old, non-custom components compiled mode, not previously nvue file, but added nvue update file can not be used this way. Because non-custom components compiled mode if no nvue file is not packaged into weex engine, the engine can not dynamically add native. Custom components default mode on his mouth weex engine, regardless of the project are under no nvue file.
  • Native plug-in additions and changes, the same can not be used this way.

Precautions

  • Conditional compilation, only perform this upgrade logic in the App platform.
  • appid 以及版本信息等,在 HBuilderX 真机运行开发期间,均为 HBuilder 这个应用的信息,因此需要打包自定义基座或正式包测试升级功能。
  • plus.runtime.version 或者 uni.getSystemInfo() 读取到的是 apk/ipa 包的版本号,而非 manifest.json 资源中的版本信息,所以这里用 plus.runtime.getProperty() 来获取相关信息。
  • 安装 wgt 资源包成功后,必须执行 plus.runtime.restart(),否则新的内容并不会生效。
  • 如果App的原生引擎不升级,只升级wgt包时需要注意测试wgt资源和原生基座的兼容性。平台默认会对不匹配的版本进行提醒,如果自测没问题,可以在manifest中配置忽略提示,详见https://ask.dcloud.net.cn/article/35627
  • www.example.com 是一个仅用做示例说明的地址,实际应用中应该是真实的 IP 或有效域名,请勿直接复制粘贴使用。

关于热更新是否影响应用上架

应用市场为了防止开发者不经市场审核许可,给用户提供违法内容,对热更新大多持排斥态度。

但实际上热更新使用非常普遍,不管是原生开发中还是跨平台开发。

Apple曾经禁止过jspatch,但没有打击其他的热更新方案,包括cordovar、react native、DCloud。封杀jspatch其实是因为jspatch有严重安全漏洞,可以被黑客利用,造成三方黑客可篡改其他App的数据。

使用热更新需要注意:

  • 上架审核期间不要弹出热更新提示
  • 热更新内容使用https下载,避免被三方网络劫持
  • 不要更新违法内容、不要通过热更新破坏应用市场的利益,比如iOS的虚拟支付要老老实实给Apple分钱
  • 如果你的应用没有犯这些错误,应用市场是不会管的。

Guess you like

Origin www.cnblogs.com/neo-java/p/11305638.html