[英]PhoneGap: Local Notifications are not working on iOS
I'm currently trying to build an app for Android and iOS which should be able to send local notifications to the user. 我目前正在尝试为Android和iOS构建应用程序,该应用程序应该能够向用户发送本地通知。
I have managed to send local notifications on Android but I'm unable to get it working on iOS. 我已经设法在Android上发送了本地通知,但无法在iOS上运行。
When I start the app on iOS 9 then the iPhone shows a prompt which asks me to allow the app to send notifications. 当我在iOS 9上启动该应用程序时,iPhone会显示一个提示,要求我允许该应用程序发送通知。 After allowing the app to send notifications there is still no notification. 允许应用发送通知后,仍然没有通知。
On Android: Start App -> Notification with text "OK" 在Android上:启动应用程序-> 带有文本“确定”的通知
On iOS 9: Start App -> Allow to send notifications -> no notification 在iOS 9上:启动应用程序->允许发送通知-> 没有通知
I also tried to add a button to the app which triggers Notifier.notify('test')
but this didn't work. 我还尝试向应用程序添加一个按钮,该按钮触发Notifier.notify('test')
但这没有用。
I even created new Apple certificates and provisioning profiles. 我什至创建了新的Apple证书和配置文件。
I'm using this plugin: https://github.com/katzer/cordova-plugin-local-notifications 我正在使用此插件: https : //github.com/katzer/cordova-plugin-local-notifications
and also tried this one: https://build.phonegap.com/plugins/4859 并尝试了这个: https : //build.phonegap.com/plugins/4859
I'm building the app using the PhoneGap Build service. 我正在使用PhoneGap Build服务来构建应用程序。
Does anyone have an idea why it works on Android but not on iOS? 有谁知道为什么它可以在Android上运行而不能在iOS上运行?
My code: 我的代码:
config.xml: config.xml文件:
...
<plugin name="cordova-plugin-local-notifications-mm"/>
...
index.html: 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: index.js:
var app = {
initialize: function () {
this.bindEvents();
},
bindEvents: function () {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
onDeviceReady: function () {
Notifier.registerPermission();
}
};
app.initialize();
notify.js: 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
});
}
};
Just finished an ibeacon app that works on both ios and android with notifications even when app is closed or phone is restarted. 刚刚完成了一个ibeacon应用程序,该应用程序可以在ios和android上运行,并且即使在关闭应用程序或重新启动电话的情况下也可以发出通知。
Make sure to add: 确保添加:
cordova.plugins.locationManager.requestAlwaysAuthorization();
That is what did it for me. 那就是为我做的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.