160 lines
5.2 KiB
Swift
160 lines
5.2 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
|
||
|
||
// 微信
|
||
WXApi.registerApp(AppSettings.kAppsWXApiAppId, universalLink: AppSettings.kAppsUniversalLink)
|
||
|
||
|
||
// 高德地图
|
||
#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 application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
|
||
print("📱 application open url: \(url.absoluteString) host: \(url.host ?? "")")
|
||
// 处理支付宝支付结果(不限制 host,适应新版 SDK)
|
||
if url.scheme?.hasPrefix("Alipay") == true || url.host == "safepay" {
|
||
AlipaySDK.defaultService().processOrder(withPaymentResult: url) { resultDic in
|
||
print("📱 Alipay callback: \(resultDic ?? [:])")
|
||
guard let result = resultDic,
|
||
let resultStatus = result["resultStatus"] as? String,
|
||
resultStatus != "6001" else { return }
|
||
|
||
}
|
||
return true
|
||
}
|
||
else if url.host == "pay" {
|
||
return WXApi.handleOpen(url, delegate: self)
|
||
}
|
||
|
||
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
|
||
}
|
||
}
|
||
}
|
||
|
||
extension AppDelegate: WXApiDelegate {
|
||
func onReq(_ req: BaseReq) {
|
||
print(req)
|
||
}
|
||
|
||
func onResp(_ resp: BaseResp) {
|
||
if resp.isKind(of: PayResp.self),
|
||
let response: PayResp = resp as? PayResp {
|
||
print("===================== WxPay =====================")
|
||
print(response.errStr)
|
||
if response.errCode == 0 { // 支付成功
|
||
DispatchQueue.global().async {
|
||
DispatchQueue.main.async {
|
||
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|