Use main thread operation to only allow one remote notification at a time to run.
This commit is contained in:
parent
f193b6da1a
commit
d30987ca0a
|
@ -24,6 +24,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
|
||||||
private var syncBackgroundUpdateTask = UIBackgroundTaskIdentifier.invalid
|
private var syncBackgroundUpdateTask = UIBackgroundTaskIdentifier.invalid
|
||||||
|
|
||||||
var syncTimer: ArticleStatusSyncTimer?
|
var syncTimer: ArticleStatusSyncTimer?
|
||||||
|
private let remoteNotificationoperationQueue = MainThreadOperationQueue()
|
||||||
|
|
||||||
var shuttingDown = false {
|
var shuttingDown = false {
|
||||||
didSet {
|
didSet {
|
||||||
|
@ -111,14 +112,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
|
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completion: @escaping (UIBackgroundFetchResult) -> Void) {
|
||||||
DispatchQueue.main.async {
|
let op = RemoteNotificationOperation(userInfo: userInfo, completion: completion)
|
||||||
self.resumeDatabaseProcessingIfNecessary()
|
remoteNotificationoperationQueue.add(op)
|
||||||
AccountManager.shared.receiveRemoteNotification(userInfo: userInfo) {
|
|
||||||
self.suspendApplication()
|
|
||||||
completionHandler(.newData)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func applicationWillTerminate(_ application: UIApplication) {
|
func applicationWillTerminate(_ application: UIApplication) {
|
||||||
|
@ -395,3 +391,31 @@ private extension AppDelegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class RemoteNotificationOperation: MainThreadOperation {
|
||||||
|
|
||||||
|
// MainThreadOperation
|
||||||
|
public var isCanceled = false
|
||||||
|
public var id: Int?
|
||||||
|
public weak var operationDelegate: MainThreadOperationDelegate?
|
||||||
|
public var name: String? = "RemoteNotificationOperation"
|
||||||
|
public var completionBlock: MainThreadOperation.MainThreadOperationCompletionBlock?
|
||||||
|
|
||||||
|
private var userInfo: [AnyHashable : Any]
|
||||||
|
private var completion: (UIBackgroundFetchResult) -> Void
|
||||||
|
|
||||||
|
init(userInfo: [AnyHashable : Any], completion: @escaping (UIBackgroundFetchResult) -> Void) {
|
||||||
|
self.userInfo = userInfo
|
||||||
|
self.completion = completion
|
||||||
|
}
|
||||||
|
|
||||||
|
func run() {
|
||||||
|
appDelegate.resumeDatabaseProcessingIfNecessary()
|
||||||
|
AccountManager.shared.receiveRemoteNotification(userInfo: userInfo) {
|
||||||
|
appDelegate.suspendApplication()
|
||||||
|
self.completion(.newData)
|
||||||
|
self.operationDelegate?.operationDidComplete(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue