jsdw_ios/QuickLocation/AppDelegate.swift

103 lines
3.1 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 {
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
window = UIWindow(frame: UIScreen.main.bounds)
window?.backgroundColor = .white
window?.overrideUserInterfaceStyle = .light
window?.rootViewController = LaunchViewController()
window?.makeKeyAndVisible()
return true
}
}
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
}
}
}