12345678910111213141516171819202122232425 |
- import UIKit
- extension UIApplication {
- public func runInBackground(_ excute: @escaping () -> Void, expirationHandler: (() -> Void)? = nil) {
- DispatchQueue.main.async {
- let taskID: UIBackgroundTaskIdentifier
- if let expirationHandler = expirationHandler {
- taskID = self.beginBackgroundTask(expirationHandler: expirationHandler)
- } else {
- taskID = self.beginBackgroundTask(expirationHandler: { })
- }
- excute()
- self.endBackgroundTask(taskID)
- }
- }
- }
|