如何升级流星应用 [英] How to upgrade a meteor app

查看:85
本文介绍了如何升级流星应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Meteor创建的我的应用程序现在正在通过Meteor的HCP(热代码推送)进行升级,这意味着用户在重新启动该应用程序后将立即获得一个新版本,而没有任何信息或确认对话框.

My App created by Meteor is now doing upgrading by Meteor's HCP(Hot Code Push), which means the user will get a new version as soon as he restarts the App, without any information or confirm dialog.

HCP很棒,但是有两个原因有些用户不希望悄悄地升级该应用程序:

HCP is great, but there are two reasons some users don't want the App be upgraded quietly:

  1. 新版本可能具有降级或其他风险.
  2. 旧版本足以供他们使用.

所以我想知道是否有办法,可以向用户显示一个描述新版本功能的新版本对话框,并询问他是否升级.当他同意时,如果HCP在这种情况下不可用,请使用HCP进行升级工作,或者通过编写代码下载必要的软件包.

So I want to know if there is a way, I can show user a new-version-available dialog describing features of the new version, and ask him whether to upgrade or not. When he agreed, use HCP to do the upgrade work or, download the necessary package by writing code if HCP not usable in this occasion.

顺便说一句,我还有另一个问题:为什么HCP仅在Android手机上运行,​​如何使其在iOS手机上运行.

By the way I have another question related: Why HCP only work on android phone, how to make it work on iOS phone.

在此先非常感谢您回答两个问题之一,或者回答了两个问题. 谢谢.

Many thanks in advance for answering any one of the two questions, or both. Thank you.

推荐答案

顺便说一句,我还有另一个问题:为什么HCP仅在Android手机上运行,​​如何使其在iOS手机上运行.

By the way I have another question related: Why HCP only work on android phone, how to make it work on iOS phone.

HCP应该以相同的方式在所有平台上工作.

HCP should work on all platforms in the same way.

要显示提示对话框,您必须在Reload._onMigrate钩子中拦截HCP:

To show prompt dialog you have to intercept HCP in Reload._onMigrate hook:

import { Reload } from 'meteor/reload';

Reload._onMigrate(() => {
  const decision = confirm("New version is available, would you like to upgrade now?")
  return [decision]; // Return [false] to manually handle HCP
});

这是一个非常简单的示例,您可以触发漂亮的UI/UX元素来处理它.

This is a very simple example, you can trigger nice UI/UX element to handle it.

例如,我们总是在_onMigrate挂钩中返回[false].向用户显示漂亮的弹出窗口.如果用户选择立即更新,我们将触发下一个功能(您需要的选择选项):

For example we always return [false] in _onMigrate hook. Show to the user nice pop-up. And if user choose to update now, we trigger next function (pick options you need):

// Purge and reload cache for AppCache package
window.applicationCache.swapCache();
window.applicationCache.update();

// Drop ServiceWorker cache
window.caches.keys().then((keys) => {
  keys.forEach((name) => {
    window.caches.delete(name);
  });
}).catch((err) => {
  console.error('window.caches.delete', err);
});

// Unregister Service Worker
SWRegistration.unregister();

// Reload the page
if (window.location.hash || window.location.href.endsWith("#")) {
  window.location.reload();
} else {
  window.location.replace(window.location.href);
}

这篇关于如何升级流星应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆