Fixes race condition causing duplicate background refresh notifications (or none)

This commit is contained in:
Riley Testut
2023-08-18 18:01:57 -05:00
parent 7a715e0ce6
commit c97a11bbdf

View File

@@ -232,7 +232,8 @@ private extension BackgroundRefreshAppsOperation
if shouldPresentAlert
{
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: delay + 1, repeats: false)
// Using nil if delay == 0 fixes race condition where multiple notifications can appear (or none).
let trigger = delay == 0 ? nil : UNTimeIntervalNotificationTrigger(timeInterval: delay + 1, repeats: false)
let request = UNNotificationRequest(identifier: self.refreshIdentifier, content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request)