Skip to content

自动更新

¥Autoupdate

这是提供热代码推送 (HCP) 功能的 Meteor 包。

¥This is the Meteor package that provides hot code push (HCP) functionality.

每个未使用 --minimal 选项创建的 Meteor 应用都已通过 meteor-base 拥有此包,并且 HCP 应该可以开箱即用。对于那些运行 --minimal 应用并希望从此包中受益的人,只需将其与 meteor add autoupdate 一起添加即可。

¥Every Meteor application that wasn't created with the --minimal option has this package already through meteor-base and HCP should work out of the box. For those running --minimal applications and want to benefit from this package, just add it with meteor add autoupdate.

autoupdate 在你的客户端生产包上最多增加 30KB。

¥autoupdate adds up to 30KB on your client's production bundle.

使用此包,Meteor 将使用 DDP 发布一个名为 'meteor_autoupdate_clientVersions' 的集合。此集合将由用户的客户端订阅,并且每次客户端识别到已发布版本中的更改时,它都会自行刷新。

¥With this package Meteor will use DDP to publish a collection called 'meteor_autoupdate_clientVersions'. This collection will be subscribed by the user's client and every time the client identifies a change in the published version it will refresh itself.

浏览器客户端

¥Browser Client

刷新将以两种不同的方式在浏览器中发生:软更新和硬更新。如果 Meteor 识别出只有样式表发生了更改,那么它将验证用户的浏览器是否能够动态重新加载 CSS,并且将进行软更新。软更新将用新样式表替换旧样式表,而不会触发整个页面重新加载。

¥The refresh will happen in the browser in two different ways: a soft update, and a hard update. If Meteor identifies that only stylesheets were changed, then it will verify if the user's browser is capable of reloading CSS on the fly, and a soft update will take place. The soft update will replace the old stylesheet with the new stylesheet without triggering a full page reload.

如果服务器或客户端的编译文件发生变化,将进行硬更新:Meteor 将使用 reload 包强制完全重新加载浏览器。

¥In cases where a change in a server's or client's compiled file happens, the hard update will take place: Meteor will force a complete browser reload using the reload package.

除其他事项外,reload 包尝试重新加载应用,同时保留一些未更改的缓存文件。

¥Among other things, the reload package tries do reload the application preserving some unchanged cached files.

Cordova 客户端

¥Cordova Client

Cordova 应用没有软更新,一旦检测到更改,客户端就会完全刷新。

¥There is no soft update with Cordova apps, the client is always fully refreshed once a change is detected.

usesCleartextTraffic

从 Android 9(API 级别 28)开始,默认为 明文支持已禁用。在开发过程中,autoupdate 使用明文发布新的客户端版本。如果你的应用针对 Android 9 或更高版本,则需要创建一个 mobile-config.js 文件以启用明文使用,以使 HCP 正常工作:

¥Starting with Android 9 (API level 28), cleartext support is disabled by default. During development autoupdate uses cleartext to publish new client versions. If your app targets Android 9 or greater, it will be necessary to create a mobile-config.js file enabling the use of cleartext in order to have HCP working:

js
App.appendToConfig(`<edit-config file="app/src/main/AndroidManifest.xml"
                     mode="merge"
                     target="/manifest/application"
                     xmlns:android="http://schemas.android.com/apk/res/android">
        <application android:usesCleartextTraffic="true"></application>
    </edit-config>
`);

--mobile-server

此外,为了使 HCP 功能正常工作,还必须使用 --mobile-server 选项提供应用服务器的地址。如果你在模拟器上测试你的应用,则应该使用 meteor run android --mobile-server 10.0.2.2:3000 运行它。如果你在真实设备上运行它,则应用服务器和设备应位于同一网络上,并且你应该使用 meteor run android --mobile-server XXX.XXX.XXX.XXX 运行你的应用,其中 XXX.XXX.XXX.XXX 是你的本地开发地址,例如 192.168.1.4。

¥Additionally, for the HCP functionality to work it is also mandatory to provide the address for the application server with --mobile-server option. If you're testing your app on an emulator you should run it with meteor run android --mobile-server 10.0.2.2:3000. If you're running it on a real device, the application server and the device should be on the same network, and you should run your app with meteor run android --mobile-server XXX.XXX.XXX.XXX where XXX.XXX.XXX.XXX is your local development address, e.g. 192.168.1.4.

要更好地了解 HCP 如何为已发布到生产的移动应用工作,请参阅 移动设备上的热门代码推送

¥To have a better understanding of how HCP works for mobile apps already published to production refer to Hot code push on mobile