jQuery Mobile+PhoneGapiOS 11:阻止尝试使用 history.replaceState() 更改会话历史记录 URL

jQueryMobile+PhoneGap+iOS 11: Blocked attempt to use history.replaceState() to change session history URL

从 iPhone OS 11.3 开始,我的应用出现以下错误:

SecurityError: Blocked attempt to use history.replaceState() to change session history URL from file:///var/containers/Bundle/Application/E73A3E4A-D961-4943-BAA3-7845E755F6A0/myplaceonline.app/www/index.html#/?phonegap=true to https://myplaceonline.com/?phonegap=true. Protocols, domains, ports, usernames, and passwords must match.
url:
file:///var/containers/Bundle/Application/E73A3E4A-D961-4943-BAA3-7845E755F6A0/myplaceonline.app/www/js/jquery.mobile-1.4.5.min.js
line #: 3 (31672)

我一直这样做的方式(并且这继续与 Android 一起工作):

  1. PhoneGap app loads JQM in an index.html page.
  2. JQM mobileinit event handler is attached which registers a pageloaded event handler which ultimately calls loadHomepage.
  3. loadHomepage 将 $.mobile.path.documentBasebase 标记的 href 属性设置到我的远程服务器 (https://myplaceonline.com/) 并调用 $.mobile.pageContainer.pagecontainer("change", "/", { allowSamePageTransition: true, transition: 'none', reloadPage: true, changeHash: true }); 加载远程主页。
  4. 这最终会促使 JQM 调用 replaceState,但由于安全错误而失败: replaceState@[native code] squash@file:///var/containers/Bundle/Application/E73A3E4A-D961-4943-BAA3-7845E755F6A0/myplaceonline.app/www/js/jquery.mobile-1.4.5.min.js:3:31672 go@file:///var/containers/Bundle/Application/E73A3E4A-D961-4943-BAA3-7845E755F6A0/myplaceonline.app/www/js/jquery.mobile-1.4.5.min.js:4:322 navigate@file:///var/containers/Bundle/Application/E73A3E4A-D961-4943-BAA3-7845E755F6A0/myplaceonline.app/www/js/jquery.mobile-1.4.5.min.js:4:1598

以上所有的目的是为了让我不会离开 file:///,因为如果我这样做,我将失去对所有原生 phone JS API 的访问权限PhoneGap。这适用于旧版本的 iOS 并继续适用于 Android.

有没有其他方法可以解决新版本 iOS 上更严格的安全问题?或者,我看到像 https://github.com/jquery/jquery-mobile/issues/5465 这样的问题建议禁用历史记录的方法,我想知道这是否是另一种解决方法,我会失去什么?

将以下代码添加到 mobileinit 处理程序可以解决问题:

$.mobile.hashListeningEnabled = false;
$.mobile.pushStateEnabled = false;
$.mobile.changePage.defaults.changeHash = false;