phonegap adobe ios iPad deviceReady 在显示通知之前未触发

phonegap adobe ios iPad deviceReady not fired until notifications shown

启动应用程序时未触发 deviceReady 事件。

将通知列表从屏幕顶部向下拖动然后松开会触发 deviceReady。

同样,尝试在 inAppBrowser 中显示页面直到通知被向下拖动并释放才会显示。

config.xml 中的关键要素是:-

  <gap:plugin name="cordova-plugin-whitelist" version="1.0.0" source="npm" />
  <gap:plugin name="cordova-plugin-inappbrowser" source="npm" version="1.0.1" />
  <gap:plugin name="cordova-plugin-device" source="npm" version="1.0.1" />
  <preference name="permissions" value="none"/>
  <preference name="fullscreen" value="true" />
  <preference name="exit-on-suspend" value="true" />

Html:-

<!DOCTYPE html >
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Home</title>
    <meta http-equiv="Content-Security-Policy" ....  />
</head>
<body >
<div id="idSplash" class="textCenter" >
    <div id="idSplashHeader">
        <div class="headerImg"></div>
    </div>
    <div>
        <div id="idSplashMessage">Starting up ...</div>
    </div>
    <div id="idSplashBody"></div>
    <div id="idSplashFooter"><a id="idTestLink" href="javascript:null" target="_blank">Click here for google</a></div>
</div>

<!-- ************************************************************************** -->
<script src="js/jquery-2.0.3.min.js" type="text/JavaScript" ></script>
<script type="text/JavaScript">
    $(document).ready(function () {
        function onReady() {
            $("#idSplashMessage").text("deviceReady");
            alert("deviceReady");
        }
        document.addEventListener("deviceReady", onReady, false);
        $("#idTestLink").click(function () {
            var win = window.open(encodeURI("http://www.google.co.uk"), '_blank', 'location=yes');
            return false;
        });
    });
</script>
<script src="cordova.js" type="text/JavaScript"></script>
</body>
</html>

@Grebe, 这是 Cordova/Phonegap.

新开发者的常见误解

发件人:Top Mistakes by Developers new to Cordova/Phonegap

4.在代码中,没有监听 'deviceready' 事件。

(...) the section of documentation we need.

This is a very important event that every Cordova application should use.

Cordova consists of two code bases: native and JavaScript. While the native code is loading, a custom loading image is displayed. However, JavaScript is only loaded once the DOM loads. This means your web application could, potentially, call a Cordova JavaScript function before it is loaded.

The Cordova deviceready event fires once Cordova has fully loaded. After the device has fired, you can safely make calls to Cordova function.

这意味着您必须在调用任何其他库之前执行此操作。

这也意味着您需要在 jquery.

之前加载 cordova.js

示例

function onLoad() {
    document.addEventListener("deviceready", onDeviceReady, false);
}
// _OR_ JUST
document.addEventListener("deviceready", onDeviceReady, false);

// Cordova is loaded and it is now safe to make calls Cordova methods
//
function onDeviceReady() {
    document.addEventListener("pause", onPause, false);
    $(document).ready(function () {
        // Call the usual stuff.
    }
}

问题的根源在于 html 中包含了内容安全策略。

虽然我相信 CSP 是完全有效的,并且没有对 Android 造成任何问题,但我删除了它,使 IOS 版本可以工作。

首先添加了 CSP,因为白名单插件的错误日志表明它是必需的。