暂无描述

UIApplicationExt.swift 710B

12345678910111213141516171819202122232425
  1. //
  2. // UIApplicationExt.swift
  3. // ExtensionKit
  4. //
  5. // Created by FFIB on 2017/9/14.
  6. // Copyright © 2017年 FFIB. All rights reserved.
  7. //
  8. import UIKit
  9. extension UIApplication {
  10. public func runInBackground(_ excute: @escaping () -> Void, expirationHandler: (() -> Void)? = nil) {
  11. DispatchQueue.main.async {
  12. let taskID: UIBackgroundTaskIdentifier
  13. if let expirationHandler = expirationHandler {
  14. taskID = self.beginBackgroundTask(expirationHandler: expirationHandler)
  15. } else {
  16. taskID = self.beginBackgroundTask(expirationHandler: { })
  17. }
  18. excute()
  19. self.endBackgroundTask(taskID)
  20. }
  21. }
  22. }