我正在使用插件在ionic 2应用程序中处理本地通知-ionic cordova plugin add cordova-plugin-local-notificationnpm install @ionic-native/local-notifications该通知在ios设备中运行得非常好,但是对于android来说却显示出意外的行为。异常行为- 在设定的时间重复同一天的通知。当前行为 -通知持续一分钟。我的要求是在每周的特定日期重复由用户设置的本地通知,该通知也应在用户设置的同一天和同一时间重复。这是我的代码段-makeLocalNotificationOn(mainDayNotifyObj, index) { let currentDate = new Date(); let currentDay = currentDate.getDay(); // Sunday = 0, Monday = 1, etc. let indexOfDay; for (let i = 0; i < this.remainderDaysArray.length; i++) { if (mainDayNotifyObj.dayName == this.remainderDaysArray[i]) { indexOfDay = i; break; } } let setTime = mainDayNotifyObj.time.split(":"); let hours = parseInt(setTime[0]); let minutes = parseInt(setTime[1]); let firstNotificationTime = new Date(); let dayDifference = indexOfDay - currentDay; if (dayDifference < 0) { dayDifference = dayDifference + 7; // for cases where the day is in the following week } firstNotificationTime.setHours(firstNotificationTime.getHours() + (24 * (dayDifference))); firstNotificationTime.setHours(hours); firstNotificationTime.setMinutes(minutes); let weekDay = firstNotificationTime.getDay(); let remainderObj = { id: index, title: 'Hello', text: 'Its time', foreground: true, trigger: {every: {weekday: weekDay, hour: hours, minute: minutes},firstAt: firstNotificationTime} }; this.notificationArray.push(remainderObj); this.platform.ready().then(() => { this.localNotifications.schedule(this.notificationArray); });}任何帮助将不胜感激。谢谢
2 回答
qq_花开花谢_0
TA贡献1835条经验 获得超7个赞
我通过修改触发器对象的值解决了我的问题。
我用来触发通知的其余对象有一些更改。
这是代码段-
remainderObj = {
id: index,
title: 'Hello',
text: 'Its time',
foreground: true,
trigger{every{weekday:weekDay,hour:hours,minute:minutes},firstAt: firstNotificationTime,count:1}
}
该计数属性所做的工作时,计数= 1所触发的通知只有一次,在Android设备。
添加回答
举报
0/150
提交
取消