[cherry] [FABRIC-12673] [ios] Crash fix.

This commit is contained in:
Ilya Grechuhin 2018-03-06 22:51:57 +03:00 committed by Roman Kuznetsov
parent 3cfbadc7b1
commit f45f16e2e4

View file

@ -8,18 +8,24 @@
var completionHandler: BackgroundFetchScheduler.FetchResultHandler!
func start() {
backgroundTaskIdentifier = UIApplication.shared.beginBackgroundTask(expirationHandler: {
self.finish(.failed)
})
if backgroundTaskIdentifier != UIBackgroundTaskInvalid {
queue.async(execute: block)
DispatchQueue.main.async {
self.backgroundTaskIdentifier = UIApplication.shared.beginBackgroundTask(expirationHandler: {
self.finish(.failed)
})
if self.backgroundTaskIdentifier != UIBackgroundTaskInvalid {
self.queue.async(execute: self.block)
}
}
}
func finish(_ result: UIBackgroundFetchResult) {
guard backgroundTaskIdentifier != UIBackgroundTaskInvalid else { return }
UIApplication.shared.endBackgroundTask(backgroundTaskIdentifier)
backgroundTaskIdentifier = UIBackgroundTaskInvalid
completionHandler(result)
DispatchQueue.main.async {
UIApplication.shared.endBackgroundTask(self.backgroundTaskIdentifier)
self.backgroundTaskIdentifier = UIBackgroundTaskInvalid
self.queue.async {
self.completionHandler(result)
}
}
}
}