From e77b35f0db030aa7e9f8f41d690a10f23e4cac69 Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Wed, 31 Jul 2019 14:34:04 -0700 Subject: [PATCH] [AltStore] Fixes duplicate alerts when refreshing in background --- AltStore/AppDelegate.swift | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/AltStore/AppDelegate.swift b/AltStore/AppDelegate.swift index 4f6062db..09a47bea 100644 --- a/AltStore/AppDelegate.swift +++ b/AltStore/AppDelegate.swift @@ -383,9 +383,15 @@ private extension AppDelegate if delay > 0 { DispatchQueue.global().asyncAfter(deadline: .now() + delay) { - // If app is still running at this point, we schedule another notification with same identifier. - // This prevents the currently scheduled notification from displaying, and starts another countdown timer. - scheduleFinishedRefreshingNotification() + UNUserNotificationCenter.current().getPendingNotificationRequests() { (requests) in + // If app is still running at this point, we schedule another notification with same identifier. + // This prevents the currently scheduled notification from displaying, and starts another countdown timer. + // First though, make sure there _is_ still a pending request, otherwise it's been cancelled + // and we should stop polling. + guard requests.contains(where: { $0.identifier == identifier }) else { return } + + scheduleFinishedRefreshingNotification() + } } } }