6

我想做的是制作一个 iOS PhoneGap/Cordova 应用程序,它唯一要做的就是加载一个外部 URL 并启用 PushNotifications。

看来我可以分开做,但不能一起做。

对于 PushNotifications,我使用了一个插件,它似乎工作得很好。

但是,当我尝试从 index.html 打开外部 URL 时,PushNotification 不起作用。

我正在使用本教程来启用 Push iOS PhoneGap/Cordova Push

在我下载示例代码后,我试图使用这样的东西:

<!DOCTYPE html>
<html>
    <head>
        <title>InAppBrowser.addEventListener Example</title>

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

            // Wait for Cordova to load
            //
            document.addEventListener("deviceready", onDeviceReady, false);

            // Cordova is ready
            //
            function onDeviceReady() {
                var ref = window.open('http://apache.org', '_blank', 'location=yes');
                ref.addEventListener('loadstart', function() { alert('start: ' + event.url); });
                ref.addEventListener('loadstop', function() { alert('stop: ' + event.url); });
                ref.addEventListener('exit', function() { alert(event.type); });
            }

            </script>
    </head>
    <body>
    </body>
</html>

我包括启用推送所需的脚本 index.js 和 pushnotifications.js。

但我只能看到 URL 加载并且未启用推送。

如果我尝试此操作,则启用推送:

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name = "format-detection" content = "telephone=no"/>
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width;" />
        <title>Push Notification Tester</title>
        <link href="css/index.css" rel="stylesheet" />
    </head>
    <body>
        <script src="cordova-2.5.0.js"></script>
        <script src="js/PushNotification.js"></script>
        <script src="js/index.js"></script>
        <script type="text/javascript">
            console.log("Test " + app);
            app.initialize();
            </script>

    </body>
</html>

但当然在这个例子中,我没有使用我想要的外部 URL。那么我将如何在这段代码中添加外部 URL 函数以同时具有外部 url 和 push ?

有任何想法吗?

4

0 回答 0