You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

129 lines
4.2 KiB

//
// 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 {
}