forked from organicmaps/organicmaps
[cherry] [FABRIC-12673] [ios] Crash fix.
This commit is contained in:
parent
3cfbadc7b1
commit
f45f16e2e4
1 changed files with 14 additions and 8 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue