我尝试使用PhoneGap平台打包原生iOS应用。我在config.xml文件中添加了Cordova库以获取本地通知。
我想安排两个每日通知(一个早上和一个晚上)。当我提醒window.plugin.notification.local.add({message:' Great app!'})时,它有效。但是,当加载应用程序时,即使我为这两者设置了自定义日期和时间,也只会在平板电脑通知中显示window.plugin.notification.local.add。
另外,cordova.plugins.notification.local.schedule函数不起作用。
我的问题是 1-为什么cordova.plugins.notification.local.schedule函数不会触发任何内容? 2-为什么window.plugin.notification.local.add不安排上午通知? 3- cordova.plugins和window.plugin有什么区别?
如果有人能帮助我,我感激不尽......
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript">
setTimeout(function() { init(); }, 500);//1/2 seconds
//
function init() {
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady() {
//alert('hello matt');
// Now safe to use the Cordova API
//window.plugin.notification.local.add({ message: 'Great app3!' });
//user premission
window.plugin.notification.local.promptForPermission();
//
var d = new Date();
d.setHours(10);
d.setMinutes(0);
d.setSeconds(0);
window.plugin.notification.local.add({
id: 1, // A unique id of the notifiction
date: d, // This expects a date object
message: 'Make sure to check Today’s Metric Insight for powerful tools that will help to transform you into the most fit, energetic, healthiest version of yourself. ', // The message that is displayed
title: 'TheBigPicture', // The title of the message
repeat: 'daily', // Either 'secondly', 'minutely', 'hourly', 'daily', 'weekly', 'monthly' or 'yearly'
autoCancel: true, // Setting this flag and the notification is automatically canceled when the user clicks it
});
/*
badge: Number, // Displays number badge to notification
sound: String, // A sound to be played
json: String, // Data to be passed through the notification
ongoing: Boolean, // Prevent clearing of notification (Android only)
*/
//
var d2 = new Date();
d2.setHours(19);
d2.setMinutes(0);
d2.setSeconds(0);
window.plugin.notification.local.add({
id: 2, // A unique id of the notifiction
date: d2, // This expects a date object
message: 'Make sure to update your daily Accountability Tracker, and complete your 100 Day Challenge daily survey. ', // The message that is displayed
title: 'TheBigPicture', // The title of the message
repeat: 'daily', // Either 'secondly', 'minutely', 'hourly', 'daily', 'weekly', 'monthly' or 'yearly'
autoCancel: true, // Setting this flag and the notification is automatically canceled when the user clicks it
});
//window.plugin.notification.local.add({ message: 'Great app!' });
cordova.plugins.notification.local.schedule([{
id: 1,
title: 'TheBigPicture',
text: 'Make sure to check Today’s Metric Insight. ',
at: _10_am,
every: 'day'
}, {
id: 2,
title: 'TheBigPicture',
text: 'Make sure to update your daily Accountability Tracker.',
at: _7_pm,
every: 'day'
}]);
//
cordova.plugins.notification.local.on("schedule", function(notification) {
alert('fourth');
alert("scheduled: " + notification.id);
});
}//end of onDeviceReady function
//
</script>
<script>
&#13;