【问题标题】:PhoneGap: Local Notifications are not working on iOSPhoneGap:本地通知在 iOS 上不起作用
【发布时间】:2015-12-10 13:27:56
【问题描述】:

我目前正在尝试为 Android 和 iOS 构建一个应用程序,它应该能够向用户发送本地通知。

我已设法在 Android 上发送本地通知,但无法在 iOS 上运行。

当我在 iOS 9 上启动应用程序时,iPhone 会显示一个提示,要求我允许应用程序发送通知。允许应用发送通知后,仍然没有通知。

在 Android 上: 启动应用 -> 带有文本“OK”的通知

在 iOS 9 上: 启动应用 -> 允许发送通知 -> 无通知

我还尝试向应用程序添加一个触发Notifier.notify('test') 的按钮,但这不起作用。

我什至创建了新的 Apple 证书和配置文件。

我正在使用这个插件:https://github.com/katzer/cordova-plugin-local-notifications

也试过这个:https://build.phonegap.com/plugins/4859

我正在使用 PhoneGap Build 服务构建应用程序。

有谁知道为什么它可以在 Android 上运行而在 iOS 上不行?

我的代码:

config.xml:

...
<plugin name="cordova-plugin-local-notifications-mm"/>
...

index.html:

<script src="cordova.js"></script>
<script src="local-notification.js"></script>
<script src="js/index.js"></script>
<script src="js/notify.js"></script>

index.js:

var app = {
    initialize: function () {
        this.bindEvents();
    },
    bindEvents: function () {
        document.addEventListener('deviceready', this.onDeviceReady, false);
    },
    onDeviceReady: function () {
        Notifier.registerPermission();
    }
};
app.initialize();

notify.js:

var Notifier = {
    registerPermission: function () {
        window.plugin.notification.local.registerPermission(function (granted) {
            Notifier.notify('OK');
        });
    },
    notify: function (message) {
        var now = new Date();
        window.plugin.notification.local.add({
            id: parseInt(new Date().getTime()),
            message: message,
            date: now
        });
    }
};

【问题讨论】:

  • 如果您找到解决方案,请告诉我们!

标签: ios iphone cordova phonegap-plugins phonegap-build


【解决方案1】:

刚刚完成了一个可在 ios 和 android 上运行的 ibeacon 应用程序,即使在应用程序关闭或手机重启时也会收到通知。

请务必添加:

cordova.plugins.locationManager.requestAlwaysAuthorization();

这就是为我做的。

【讨论】:

猜你喜欢
  • 2017-06-23
  • 1970-01-01
  • 1970-01-01
  • 2017-11-20
  • 1970-01-01
  • 1970-01-01
  • 2014-08-18
  • 2020-09-22
  • 2015-07-10
相关资源
最近更新 更多