AppDelegate.swift 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //
  2. // AppDelegate.swift
  3. // Introduce
  4. //
  5. // Created by 胡志强 on 2021/11/29.
  6. //
  7. import BFCommonKit
  8. import BFMaterialKit
  9. import UIKit
  10. import AppTrackingTransparency
  11. import AdSupport
  12. @main
  13. class AppDelegate: UIResponder, UIApplicationDelegate {
  14. var window: UIWindow?
  15. var isEnterBack: Bool = false // 进入后台
  16. var notificationUserInfo: [String: Any]?
  17. func application(_: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
  18. if launchOptions?.keys.contains(UIApplication.LaunchOptionsKey.remoteNotification) ?? false {
  19. notificationUserInfo = launchOptions?[UIApplication.LaunchOptionsKey.remoteNotification] as? [String: Any]
  20. if notificationUserInfo != nil && notificationUserInfo?.keys.contains("type") ?? false {
  21. PQSingletoMemoryUtil.shared.coldLaunchType = .coldLaunchType_pushRecall
  22. }
  23. }
  24. // 配置启动项
  25. DispatchQueue.global().async {
  26. // 初始化配置
  27. INAppConfigUtil.pageConfig()
  28. #if DEBUG
  29. #else
  30. INAppConfigUtil.applicationConfig(launchOptions:launchOptions)
  31. #endif
  32. }
  33. // BFMaterialConfig.shared.choseType = .single
  34. return true
  35. }
  36. // MARK: 前后台 Lifecycle
  37. func applicationWillResignActive(_: UIApplication) {}
  38. func applicationDidEnterBackground(_: UIApplication) {
  39. // 热启动重新生成SubSesstionId
  40. isEnterBack = true
  41. DispatchQueue.global().async {
  42. PQSingletoMemoryUtil.shared.createSubSesstionId()
  43. BFConfig.shared.subSessionId = PQSingletoMemoryUtil.shared.subSessionid
  44. }
  45. }
  46. func application(_: UIApplication, supportedInterfaceOrientationsFor _: UIWindow?) -> UIInterfaceOrientationMask {
  47. return UIInterfaceOrientationMask.portrait
  48. }
  49. func applicationDidBecomeActive(_: UIApplication) {
  50. BFLog(message: "applicationDidBecomeActive")
  51. if isEnterBack {
  52. // 热启动
  53. PQSingletoMemoryUtil.shared.isColdLaunch = false
  54. // 热启动上报
  55. INAppConfigUtil.appLaunchReportUpload(isHotLaunch: true)
  56. isEnterBack = false
  57. }
  58. UIApplication.shared.keyWindow?.isUserInteractionEnabled = true
  59. requestPromission()
  60. }
  61. func requestPromission(){
  62. if #available(iOS 14.0, *) {
  63. let status = ATTrackingManager.trackingAuthorizationStatus
  64. switch status {
  65. case .denied:
  66. print("用户拒绝IDFA")
  67. case .authorized:
  68. print("用户允许IDFA")
  69. case .notDetermined:
  70. print("用户未做选择或未弹窗IDFA")
  71. ATTrackingManager.requestTrackingAuthorization { _ in
  72. }
  73. default:
  74. break
  75. }
  76. } else {
  77. if ASIdentifierManager.shared().isAdvertisingTrackingEnabled {
  78. print("用户开启了广告追踪IDFA")
  79. } else {
  80. print("用户关闭了广告追踪IDFA")
  81. }
  82. }
  83. }
  84. }