Phonegap本地通知插件不起作用

时间:2017-06-18 12:39:42

标签: javascript android cordova notifications phonegap-plugins

我是初学者,创建了一个phonegap应用,我需要使用本地通知。我使用了https://github.com/katzer/cordova-plugin-local-notifications,但似乎无法让它发挥作用。我完全失去了这一点,所以我一步一步地把我所做的一切都给了。

我做了什么: 导航到my_project_folder/plugins并运行命令phonegap plugin add https://github.com/katzer/cordova-plugin-local-notifications。执行的命令没有任何错误。

名为de.appplant.cordova.plugin.local-notification的文件夹现在位于我的插件文件夹中。行<plugin name="de.appplant.cordova.plugin.local-notification" spec="https://github.com/katzer/cordova-plugin-local-notifications" />自动添加到config.xml

在我的应用程序的index.js中,出于测试目的,我添加了以下代码:

var d = new Date();
d.addSeconds(20); 
cordova.plugins.notification.local.schedule({
                id: 1999,
                title: 'Sample',
                message: 'checking',
                date: d
});

所以我会在运行应用程序后20秒收到通知。在运行时(在我的浏览器中)但是我收到了错误Uncaught TypeError: Cannot read property 'notification' of undefined

我做错了什么,我该怎么做才能解决这个错误?在一些在线示例中,代码以window.plugin.notification.local.add({..开头,但尝试为我提供相同的错误。

1 个答案:

答案 0 :(得分:0)

尝试

var d = new Date();

//Are you sure about this addSeconds()?
d.addSeconds(20); 

cordova.plugins.notification.local.schedule({
                id: 1999,
                title: 'Sample',
                text: 'checking',
                trigger: {at: d}
});
相关问题