115 lines
3.6 KiB
Swift
115 lines
3.6 KiB
Swift
//
|
|
// AppDelegate.swift
|
|
// QuickLocation
|
|
//
|
|
// Created by 林 on 2026/5/25.
|
|
//
|
|
|
|
import UIKit
|
|
import IQKeyboardManagerSwift
|
|
#if !targetEnvironment(simulator)
|
|
import GeYanSdk
|
|
import AMapFoundationKit
|
|
#endif
|
|
|
|
@main
|
|
class AppDelegate: UIResponder, UIApplicationDelegate {
|
|
|
|
var window: UIWindow?
|
|
|
|
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
|
|
|
|
setupLocation()
|
|
ApiManager.shared.setup()
|
|
AppRouter.shared.setup()
|
|
|
|
return true
|
|
}
|
|
|
|
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
|
// Override point for customization after application launch.
|
|
|
|
IQKeyboardManager.shared.isEnabled = true
|
|
IQKeyboardManager.shared.enableAutoToolbar = false
|
|
IQKeyboardManager.shared.resignOnTouchOutside = true
|
|
|
|
// 高德地图
|
|
#if !targetEnvironment(simulator)
|
|
AMapServices.shared().apiKey = AppSettings.kAppsAMapAppId
|
|
#endif
|
|
|
|
// 个推
|
|
#if !targetEnvironment(simulator)
|
|
GeYanSdk.setPreLoginTimeout(10)
|
|
GeYanSdk.setEloginTimeout(10)
|
|
GeYanSdk.start(withAppId: AppSettings.kAppsGeTuiAppId) { isSuccess, error, gtcid in
|
|
print("GeYanSdk startWithAppId gtcid: \(gtcid ?? "")")
|
|
}
|
|
GeYanSdk.preGetToken { preDic in
|
|
print("preGetToken: \(preDic)")
|
|
}
|
|
#endif
|
|
|
|
// OpenIM
|
|
GroupIMService.shared.initSDK()
|
|
|
|
window = UIWindow(frame: UIScreen.main.bounds)
|
|
window?.backgroundColor = .white
|
|
window?.overrideUserInterfaceStyle = .light
|
|
window?.rootViewController = LaunchViewController()
|
|
window?.makeKeyAndVisible()
|
|
|
|
return true
|
|
}
|
|
|
|
func setupLocation() {
|
|
let manager = AuthorizeManager.manager(type: .locationWhenInUse)
|
|
if manager?.authorizeStatus() != .authorized {
|
|
manager?.authorize(nil)
|
|
Permission.openAppSetting(title: "获取位置失败",
|
|
message: "请在iPhone的“设置-隐私-定位”选项中允许\(kAppName)访问你的位置。")
|
|
}
|
|
}
|
|
}
|
|
|
|
extension AppDelegate {
|
|
/// 重置MainTabbarViewController
|
|
func showMainViewController() {
|
|
window?.rootViewController = MainTabBarController()
|
|
}
|
|
}
|
|
|
|
extension AppDelegate {
|
|
|
|
static var shared: AppDelegate {
|
|
UIApplication.shared.delegate as! AppDelegate
|
|
}
|
|
|
|
static var keyWindow: UIWindow? {
|
|
UIApplication.shared.windows.filter { $0.isKeyWindow }.first
|
|
}
|
|
|
|
static var rootViewController: UIViewController? {
|
|
getRootViewController(keyWindow?.rootViewController)
|
|
}
|
|
|
|
static func getRootViewController(_ inViewController: UIViewController?) -> UIViewController? {
|
|
|
|
var rootViewController: UIViewController? = inViewController
|
|
|
|
while inViewController?.presentedViewController != nil {
|
|
rootViewController = rootViewController?.presentedViewController
|
|
}
|
|
|
|
guard let rootVc = rootViewController else { return nil }
|
|
|
|
if rootVc.isKind(of: UINavigationController.self) {
|
|
return getRootViewController((rootVc as? UINavigationController)?.visibleViewController)
|
|
} else if rootVc.isKind(of: UITabBarController.self) {
|
|
return getRootViewController((rootVc as? UITabBarController)?.selectedViewController)
|
|
} else {
|
|
return rootVc
|
|
}
|
|
}
|
|
}
|