[英]Trigger local notification for iOS - Cordova/Phonegap
I am using this plugin and trying to trigger local notification for my Cordova iOS app with Local notifications plugin . 我正在使用此插件,并尝试使用本地通知插件为我的Cordova iOS应用触发本地通知。
I dd following steps: 我dd遵循以下步骤:
Installed plugin: cordova plugin add de.appplant.cordova.plugin.local-notification@0.7.7
安装的插件:
cordova plugin add de.appplant.cordova.plugin.local-notification@0.7.7
Updated config.xml : gap:plugin name="de.appplant.cordova.plugin.local-notification"
更新了config.xml :
gap:plugin name="de.appplant.cordova.plugin.local-notification"
Added the following JavaScript in head tag for 在head标签中添加了以下JavaScript,用于
index.html index.html
plugin.notification.local.promptForPermission(function (granted) {
alert("promptForPermission: "+granted);
});
plugin.notification.local.hasPermission(function (granted) {
alert("hasPermission: "+granted);
});
Code for that looks like this: 该代码如下所示:
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");
};
I do see a prompt for user's permission and the alert from hasPermission method shows the value as true. 我确实看到提示用户输入权限的消息,并且hasPermission方法的警报将值显示为true。 But I am still not able to get the actual local notification I am trying to set by clicking a button.
但是我仍然无法通过单击按钮来获取要设置的实际本地通知。 I have already updated the APPLocalNotification.m file for the this issue by copying this fix.
通过复制此修补程序,我已经针对此问题更新了APPLocalNotification.m文件。
I don't see any more errors in the console log but I am still not able to trigger a local notification. 我在控制台日志中看不到任何其他错误,但是我仍然无法触发本地通知。
You should check if the device is ready ( document.addEventListener('deviceready', function () { ) and also check if the plugin is correctly added $ cordova plugin ls. 您应该检查设备是否准备就绪(document.addEventListener('deviceready',function(){),还应检查插件是否已正确添加$ cordova plugin ls。
Make sure you have "< script type="text/javascript" src="cordova.js"> " in your html . 确保您的html中有“ <<script type =“ text / javascript” src =“ cordova.js”>“。
Good luck! 祝好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.