【问题标题】:Trigger local notification for iOS - Cordova/Phonegap触发 iOS 的本地通知 - Cordova/Phonegap
【发布时间】:2015-03-08 22:05:21
【问题描述】:

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

我会遵循以下步骤:

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

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

  3. 的 head 标签中添加了以下 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 秒后创建本地通知。

代码如下所示:

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 修复更新了 this issueAPPLocalNotification.m 文件。

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

【问题讨论】:

  • 那么该函数上的_alert_s 都显示了吗?另外,您是否尝试过在显示通知之前增加一些时间?或者更好的是,尝试不使用日期选项,因为它应该会立即显示。
  • @sanfor 是的,两个 javascript 警报都已执行并显示。我什至按照您的建议尝试不使用日期选项,但也没有运气。
  • 您是否在添加通知之前确定触发了 deviceReady 事件?此外,您正在使用 CLI 来构建它而不是 PhoneGap Build,对吧?第 2 步是完全没有必要的,因为它仅适用于 PhoneGap Build 应用程序。
  • @sanfor 我在 document.addEventListener('deviceready', function() {...} 中有 plugin.notification.local.hasPermission(function (granted) 并将 hasPermission 值显示为 true 。我正在尝试从需要在按下按钮时执行的外部函数设置本地通知。是的,我正在使用 CLI 构建而不是 phonegap 构建。我将更新 config.xml,因为这不是必需的。谢谢到目前为止你的帮助。
  • 我想我也看到了同样的问题,可能是由于最近的 iOS 更新?我最近才更新到 iOS 8..

标签: javascript ios cordova localnotification


【解决方案1】:

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

确保你有“ " 在你的 html 中。

祝你好运!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-12
    相关资源
    最近更新 更多