|
@@ -6,16 +6,21 @@
|
|
|
//
|
|
|
|
|
|
import UIKit
|
|
|
-import SQLite3
|
|
|
+
|
|
|
@main
|
|
|
class AppDelegate: UIResponder, UIApplicationDelegate {
|
|
|
|
|
|
var window: UIWindow?
|
|
|
-
|
|
|
+ var backgroundTaskIdentifier: UIBackgroundTaskIdentifier = .invalid
|
|
|
+
|
|
|
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
|
|
window = UIWindow(frame: UIScreen.main.bounds)
|
|
|
window?.backgroundColor = UIColor.white
|
|
|
window?.makeKeyAndVisible()
|
|
|
+
|
|
|
+ // 监听应用进入后台的通知
|
|
|
+ NotificationCenter.default.addObserver(self, selector: #selector(applicationDidEnterBackground), name: UIApplication.didEnterBackgroundNotification, object: nil)
|
|
|
+
|
|
|
initPlatform()
|
|
|
goToLoadVC()
|
|
|
return true
|
|
@@ -64,3 +69,22 @@ extension AppDelegate {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+extension AppDelegate {
|
|
|
+ @objc func applicationDidEnterBackground() {
|
|
|
+ beginBackgroundTask()
|
|
|
+ }
|
|
|
+
|
|
|
+ func beginBackgroundTask() {
|
|
|
+ backgroundTaskIdentifier = UIApplication.shared.beginBackgroundTask { [weak self] in
|
|
|
+ self?.endBackgroundTask()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func endBackgroundTask() {
|
|
|
+ if backgroundTaskIdentifier != .invalid {
|
|
|
+ UIApplication.shared.endBackgroundTask(backgroundTaskIdentifier)
|
|
|
+ backgroundTaskIdentifier = .invalid
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|