触发iOS的本地通知 - Cordova / Phonegap

时间:2015-01-10 18:55:01

标签: javascript ios cordova localnotification

我正在使用此插件并尝试使用Local notifications plugin触发我的Cordova iOS应用的本地通知。

我遵循以下步骤:

  1. 已安装的插件:cordova plugin add de.appplant.cordova.plugin.local-notification@0.7.7

  2. 更新了 config.xml gap:plugin name="de.appplant.cordova.plugin.local-notification"

  3. 的主标记中添加了以下JavaScript

    的index.html

    plugin.notification.local.promptForPermission(function (granted) {
      alert("promptForPermission: "+granted);
    });
    
    plugin.notification.local.hasPermission(function (granted) {
      alert("hasPermission: "+granted);
    });
    
    1. index.html 中设置一个按钮,以便在5秒后创建本地通知。
    2. 代码如下:

      function setLocalNotification()
      {
        alert("from setLocalNotification");
        var t = new Date();
        t.setSeconds(t.getSeconds() + 3);
      
        window.plugin.notification.local.add({
          title:   'Scheduled with delay',
          message: 'Test Message ',
          date:    t
        });
      
        alert("alert set");
       };
      

      我确实看到了用户许可的提示,并且来自hasPermission方法的警报将值显示为true。但是我仍然无法通过单击按钮获得我尝试设置的实际本地通知。我已经通过复制this issue修正更新了this APPLocalNotification.m 文件。

      我在控制台日志中没有看到任何更多错误,但我仍然无法触发本地通知。

1 个答案:

答案 0 :(得分:0)

您应该检查设备是否准备就绪(document.addEventListener(' deviceready',function(){ 并检查插件是否正确添加$ cordova plugin ls。

确保你有"<脚本类型=" text / javascript" SRC =" cordova.js"> "在你的HTML中。

祝你好运!