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
committed by Magesh K
parent e605399633
commit 9b885085c9

View File

@@ -238,7 +238,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)