|
//
// UIApplicationExt.swift
// ExtensionKit
//
// Created by FFIB on 2017/9/14.
// Copyright © 2017年 FFIB. All rights reserved.
//
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)
}
}
}
|