gpt4 book ai didi

android - 强制重新启动完整的应用程序以刷新 Cordova 中的包

转载 作者:行者123 更新时间:2023-12-05 00:09:59 31 4
gpt4 key购买 nike

我希望从应用程序本身完全重启应用程序(真正重启应用程序(满载)而不仅仅是重新呈现索引)。

这需要发生,因为一些包也需要重新初始化,这只能在完全重新启动应用程序时完成。

我试过这个包https://www.npmjs.com/package/cordova-plugin-exit这似乎不起作用。

navigator.app.exitapp() 也不是我要找的东西,或者这是否完全符合我的要求?

创建一个 cordova 包装器插件的最佳解决方案是否以不同的方式为 android 和 IOS 执行此操作?

最佳答案

您可以在 Android 上使用 restart() 执行此操作cordova-diagnostic-plugin的方法:

// Warm restart
cordova.plugins.diagnostic.restart(null, false);

// Cold restart
cordova.plugins.diagnostic.restart(null, true);

By default, a "warm" restart will be performed in which the main Cordova activity is immediately restarted, causing the Webview instance to be recreated.

However, if the cold parameter is set to true, then the application will be "cold" restarted, meaning a system exit will be performed, causing the entire application to be restarted. This is useful if you want to fully reset the native application state but will cause the application to briefly disappear and re-appear.

Note: There is no successCallback() since if the operation is successful, the application will restart immediately before any success callback can be applied.

无法在 iOS 上以编程方式重启应用程序;至少这样做可能会使您的应用程序被 App Store 拒绝。

关于android - 强制重新启动完整的应用程序以刷新 Cordova 中的包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52258488/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com