0

我正在尝试在 IOS 中创建一个 phonegap 应用程序。我已经成功创建了该项目,当运行创建的相同应用程序时运行完美,当更改为我的代码时,它没有检测到除 alert() 之外的任何 javascript 事件。

document.addEventListener('deviceready', function(){}, false);
console.log("I'm working");

这些函数在 Xcode 和 iOS 设备或模拟器中不起作用。

我创建的同一个应用程序在 android 中运行良好。

请帮我解决这个问题。

4

1 回答 1

0

我无法开始猜测为什么这适用于 Android 而不是 iOS。您确定要包含在 html 页面的头部吗?没有它,“deviceready”侦听器将无法工作。其他一切看起来都很好。phonegap 文档显示以下代码:

<!DOCTYPE html>
<html>
    <head>
        <title>Device Ready Example</title>

            <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
            <script type="text/javascript" charset="utf-8">

            // Wait for device API libraries to load
            function onLoad() {
                document.addEventListener("deviceready", onDeviceReady, false);
            }

            // device APIs are available
            function onDeviceReady() {
                // Now safe to use device APIs
                ****For testing purposes, add an alert() here to ensure it is working.****
            }

        </script>
    </head>
    <body onload="onLoad()">

    </body>
</html>
于 2013-09-23T15:03:14.930 回答