I'm experiencing a weird bug with iOS 10.2 with UNTimeIntervalNotificationTrigger
and UNUserNotificationCenterDelegate
. Basically the notification I create is getting picked up by the delegate instantly and then again at the correct internal. This only happens when the repeats property is set to true on the trigger.
Has anyone else seen this issue? Right now I'm thinking I need to check the trigger date in the delegate and compare to a stored registered date — but I want to avoid that if possible.
Sample code to create notification
let content = UNMutableNotificationContent()
content.body = "My notification message"
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 60, repeats: true)
let request = UNNotificationRequest(identifier: "MY_IDENTIFIER", content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)
UNUserNotificationCenterDelegate is fired directly after .add
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
// Code called here instantly when trigger repeats = true
// Code called again at proper interval as well (60 seconds)
}
If I change the trigger to repeats false, this doesn't happen
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 60, repeats: false)