// // AppDelegate.swift // FireBoltt // // Created by lemo. on 2020/3/1. // Copyright © 2020 Sheldon. All rights reserved. // import UIKit import UserNotifications @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate { var window: UIWindow? var httpdns: HttpDnsService? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { let screen = UIScreen.main.bounds window = UIWindow(frame: screen) Application.shared.presentInitialScreen(in: window!) /// 注册本地通知 // regisigerNotification(application) JL_Tools.openLogTextFile() // // 蓝牙库 // Bluetooth.shareInstance() // DNS httpdns = HttpDnsService(accountID: 170287) SystemAuthorityFireBoltt.shared .getLocationAuthority{ [weak self] (result) in if result{ } } return true } func applicationWillEnterForeground(_ application: UIApplication) { self.stopKeepAlive() if (UserDefaultsManagerFrieBoltt.getDeviceInfo() == nil) { return } if BluetoothFireBoltt.shareInstance()!.isConnected { NSLog("APP回到手表已连接") } else { NSLog("APP回到手表未连接") // BluetoothFireBoltt.shareInstance()!.startAndStopReconnect(true) // Bluetooth.shareInstance()?.connected(with: Bluetooth.shareInstance()?.currenModel) } } var backTask :UIBackgroundTaskIdentifier? //APP进入后台 func applicationDidEnterBackground(_ application: UIApplication) { backTask = UIApplication.shared .beginBackgroundTask(expirationHandler: { self.stopKeepAlive(); }) if BluetoothFireBoltt.shareInstance()!.isConnected { if BluetoothFireBoltt.shareInstance()?.currenModel != nil{ NSLog("APP进入后台手表已连接") if #available(iOS 13.0, *) { } else { // Fallback on earlier versions } } } } //普通申请后台时间 func stopKeepAlive(){ if (backTask != nil){ UIApplication.shared.endBackgroundTask(backTask!) backTask = .invalid } } func regisigerNotification(_ application: UIApplication){ UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { success, error in if !success { NSLog("本地通知未打开,请授权APP使用您的本地通知") } } if #available(iOS 10.0, *) { let center = UNUserNotificationCenter.current() center.delegate = self center.requestAuthorization(options: [.alert, .sound, .badge]) { (granted: Bool, error: Error?) in DispatchQueue.main.async { if granted { application.registerForRemoteNotifications() } } } } else { let settings = UIUserNotificationSettings(types: [.alert, .sound, .badge], categories: nil) application.registerForRemoteNotifications() application.registerUserNotificationSettings(settings) } } func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { NSLog("通知注册完毕") } func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) { NSLog("通知注册失败error:\(error)") } func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { completionHandler(UNNotificationPresentationOptions.alert) } } extension AppDelegate { }