AppDelegate.swift 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // AppDelegate.swift
  3. // Lanu
  4. //
  5. // Created by OneeChan on 2025/11/6.
  6. //
  7. import UIKit
  8. import CocoaLumberjackSwift
  9. import Firebase
  10. import GoogleSignIn
  11. @main
  12. class AppDelegate: UIResponder, UIApplicationDelegate {
  13. func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
  14. // Override point for customization after application launch.
  15. setupLogger()
  16. setupFirebase()
  17. LNNetworkMonitor.startMonitoring()
  18. _ = LNProfileManager.shared
  19. _ = LNIMManager.shared
  20. _ = LNGameMateManager.shared
  21. _ = LNPurchaseManager.shared
  22. _ = RechargeManager.shared
  23. _ = LNLocationManager.shared
  24. _ = LNRelationManager.shared
  25. _ = LNDeeplinkManager.shared
  26. _ = LNKeyboardManager.shared
  27. LNEventDeliver.notifyAppLaunchFinished()
  28. if let url = launchOptions?[.url] as? URL {
  29. LNDeeplinkManager.shared.handleDeepLink(url)
  30. }
  31. return true
  32. }
  33. // MARK: UISceneSession Lifecycle
  34. func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
  35. // Called when a new scene session is being created.
  36. // Use this method to select a configuration to create the new scene with.
  37. return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
  38. }
  39. func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
  40. // Called when the user discards a scene session.
  41. // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
  42. // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
  43. }
  44. }
  45. extension AppDelegate {
  46. private func setupFirebase() {
  47. #if DEBUG
  48. let plistName = "GoogleService-Info-Debug"
  49. #else
  50. let plistName = "GoogleService-Info-Release"
  51. #endif
  52. let plistPath = Bundle.main.path(forResource: plistName, ofType: "plist")!
  53. let options = FirebaseOptions(contentsOfFile: plistPath)
  54. FirebaseApp.configure(options: options!)
  55. }
  56. private func setupLogger() {
  57. #if DEBUG // 只在 Debug 模式打印到终端
  58. let logger = DDOSLogger.sharedInstance
  59. logger.logFormatter = LNLoggerFormater()
  60. DDLog.add(logger)
  61. #endif
  62. let fileLogger = DDFileLogger()
  63. fileLogger.logFormatter = LNLoggerFormater()
  64. fileLogger.rollingFrequency = 24 * 60 * 60 // 1 天轮转
  65. fileLogger.logFileManager.maximumNumberOfLogFiles = 7 // 最多保存 7 个文件
  66. fileLogger.maximumFileSize = 5 * 1024 * 1024 // 5M 最大限制
  67. DDLog.add(fileLogger)
  68. }
  69. }