PhoneGap Notification.Alert 不起作用 [英] PhoneGap Notification.Alert not working

查看:19
本文介绍了PhoneGap Notification.Alert 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我已经研究这个问题有一段时间了,但无法解决这个问题.简单的 PhoneGap 测试应用,尝试显示警报.

Okay I've been working on this issue for a while now and can't figure this thing out. Simple PhoneGap test app, trying to show an alert.

使用适用于 iOS 的 Cordova 2.9.0.我已经添加了一些简单的测试代码并在 chrome 中对其进行了测试,以查看它在哪里中断,因为它在模拟器中不起作用

Using Cordova 2.9.0 for iOS. I've added some simple test code and tested it in chrome to see where it breaks, because it isn't working in the emulator

当我在 Chrome 中测试时(当然在模拟器中结果相同,但没有显示错误消息)

When I test in the Chrome (of course same result in emulator, but no error message is showing)

  • 它应该执行 onDeviceReady
  • 它将 tb2 文本框值设置为警报之前"
  • 然后它因错误而中断:Uncaught TypeError:Cannot call method 'alert' of undefined,在这一行:navigator.notification.alert(...

它应该正确引用cordova.js,这是我的应用程序文件夹的结构:

It should be referencing the cordova.js properly, here is the structure of my app folder:

  • cordova_plugins.js
  • cordova.js
  • /规范
  • spec.html
  • config.xml
  • /css
  • home.html
  • /img
  • index.html
  • /js
  • /res

这是我的 config.xml 代码:

Here is my config.xml code:

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.blahblahblah.hello" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>Hello World</name>
    <description>
        Test blahblahblah Application
    </description>
    <author email="blahblahblah@blahblahblah.com" href="http://blahblahblah.com">
        blahblahblah
    </author>
    <access origin="*" />

    <preference name="fullscreen" value="true" />
    <preference name="webviewbounce" value="true" />

    <plugins>
        <plugin name="Notification" value="CDVNotification" />
    </plugins>
</widget>

这是我的 index.html 代码:

Here is my index.html code:

<!DOCTYPE html>
<html>
  <head>
    <title>Notification Example</title>

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

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

    // Cordova is ready
    //
    function onDeviceReady() {
        // Empty
        document.getElementById('tb1').value = 'device ready';
    }

    // alert dialog dismissed
    function alertDismissed() {
        // do something
    }

    // Show a custom alert
    //
    function showAlert() {
        document.getElementById('tb2').value = 'before alert';

        navigator.notification.alert(
            'You are the winner!',  // message
            alertDismissed,         // callback
            'Game Over',            // title
            'Done'                  // buttonName
        );
        document.getElementById('tb3').value = 'after alert';
    }

    </script>
  </head>
  <body>
    <p><a href="#" onclick="showAlert(); return false;">Show Alert</a></p>
    <input type="text" id="tb1" value="" />
    <input type="text" id="tb2" value="" />
    <input type="text" id="tb3" value="" />
  </body>
</html>

我搜索了文档,但没有找到任何关于为什么这不起作用的线索,这个问题的大多数答案都没有针对 2.9.0 版

I have searched documentation, and haven't found any clue of why this isn't working, most answers to this question don't address version 2.9.0

提前致谢.

推荐答案

我知道问题是关于 Phonegap 2.9,但是当有人寻找phonegap alert not working"时,这是 Google 吐槽的第一件事.所以这就是我为它与 Phonegap 3.0 一起工作所做的:

I know the question is about Phonegap 2.9, but that's the first thing Google spits when somebody looks for "phonegap alert not working". So here's what I did for it to work with Phonegap 3.0:

根据手册,您需要将插件添加到您的项目中.只需导航到您的项目根文件夹并编写以下命令:

According to the manual, you need to add the plugin to your project. Just navigate to your project root folder and write this command:

$phonegap 本地插件添加 https://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs.git

之后,我将其添加到我的 html 中:

After that, I added this to my html:

<script type="text/javascript" charset="utf-8" src="phonegap.js"></script>
<script>
    document.addEventListener("deviceready", onDeviceReady, true);
    function onDeviceReady() {

        navigator.notification.alert("PhoneGap is working", function(){}, "", "");
    } 
</script> 

这篇关于PhoneGap Notification.Alert 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆