我已经建立了余数应用程序设置在一个特定的时间与或不重复模式。
我一直在努力解决一个问题。任何帮助都会有助于解决这个问题。
下面是我所面临的情况
当创建余数时没有重复模式,而我正在删除剩余部分,挂起通知将被删除,但当其设置为重复模式时,挂起通知不会被删除。
下面是删除通知的代码。
UNUserNotificationCenter.current().getPendingNotificationRequests { requests in
let allNotifIds = requests.map({ $0.identifier })
let pendingTaskNotifIds = taskNotificationIds.filter({ allNotifIds.contains($0) })
UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers: pendingTaskNotifIds)
}添加通知的代码
let content = UNMutableNotificationContent()
//set badge content here (get list from db and update it.)
content.badge = NSNumber(value: getBadgeCount())
content.title="sometitle";
content.body = "body data"
content.sound = UNNotificationSound.default
let twoWeeksTrigger = UNTimeIntervalNotificationTrigger(timeInterval: TimeInterval.everyTwoWeeks, repeats: true)
let id = UUID().uuidString
let request = UNNotificationRequest(identifier: id, content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request)这是我的日志,我已经创建了两个剩余的任务(一个是非重复的任务,另一个是重复的任务)。
[<UNNotificationRequest: 0x600003dd5440; identifier: 06B35F80-9769-492A-8BFF-3108A11B1542, content: <UNNotificationContent: 0x600000786700; title: , subtitle: (null), body: Without repeat notification, summaryArgument: , summaryArgumentCount: 0, categoryIdentifier: com.example, launchImageName: , threadIdentifier: , attachments: (
), badge: 1, sound: <UNNotificationSound: 0x60000163b180>,, trigger: <UNCalendarNotificationTrigger: 0x6000033d7f40; dateComponents: <NSDateComponents: 0x6000005a0f20>
Calendar Year: 2019
Month: 1
Day: 22
Hour: 13
Minute: 53
Weekday: 3, repeats: NO>>,
<UNNotificationRequest: 0x600003dd3ae0; identifier: D33A49EC-DD3C-4090-AD86-9F16ED4EA6CC, content: <UNNotificationContent: 0x6000007852c0; title: , subtitle: (null), body: Repeat notification, summaryArgument: , summaryArgumentCount: 0, categoryIdentifier: com.example, launchImageName: , threadIdentifier: , attachments: (
), badge: 1, sound: <UNNotificationSound: 0x600001639800>,, trigger: <UNCalendarNotificationTrigger: 0x6000033d5740; dateComponents: <NSDateComponents: 0x6000005a1ef0>
Month: 1
Day: 22
Hour: 13
Minute: 54, repeats: YES>>]在删除两个任务通知后,会为重复任务触发通知,并且我的通知对象在日志中打印了重复任务对象,只删除非重复任务。这是供参考的日志。
[<UNNotificationRequest: 0x600003d2b300; identifier: D33A49EC-DD3C-4090-AD86-9F16ED4EA6CC, content: <UNNotificationContent: 0x60000079ca80; title: , subtitle: (null), body: Repeat notification, summaryArgument: , summaryArgumentCount: 0, categoryIdentifier: com.lawrence.revival.category, launchImageName: , threadIdentifier: , attachments: (
), badge: 1, sound: <UNNotificationSound: 0x60000163fde0>,, trigger: <UNCalendarNotificationTrigger: 0x6000033f9a40; dateComponents: <NSDateComponents: 0x6000005be470>
Month: 1
Day: 22
Hour: 13
Minute: 54, repeats: YES>>]发布于 2019-01-22 11:00:10
https://stackoverflow.com/questions/54304261
复制相似问题