AppDelegate.swift 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. //
  2. // AppDelegate.swift
  3. // TSLiveWallpaper
  4. //
  5. // Created by 100Years on 2024/12/19.i
  6. //
  7. import ADManager
  8. import AppTrackingTransparency
  9. import GoogleMobileAds
  10. import StoreKit
  11. import TSVideoKit
  12. import UIKit
  13. @main
  14. class AppDelegate: UIResponder, UIApplicationDelegate {
  15. var window: UIWindow?
  16. func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
  17. window = UIWindow(frame: UIScreen.main.bounds)
  18. window?.backgroundColor = UIColor.white
  19. window?.makeKeyAndVisible()
  20. goToLoadVC()
  21. initBaseDatas()
  22. initPlatform()
  23. downloadNotifaction()
  24. return true
  25. }
  26. func goToTab() {
  27. window?.rootViewController = TSTabBarController()
  28. }
  29. func goToLoadVC() {
  30. _ = TSImageDataCenter.shared
  31. window?.rootViewController = TSLaunchVC()
  32. }
  33. func initBaseDatas() {
  34. var config = TSConfiguration.default
  35. config.configurePath = "http://p.100yearslater.com/live/config"
  36. TSVideoOperator.shared.loadWithConfiguration(config: config, needJs: true)
  37. if let videoId = UserDefaults.standard.string(forKey: "lastedVideoId"),
  38. !videoId.isEmpty,
  39. let lastVideo = TSVideoOperator.shared.dataManager.fetchVideo(videoId: videoId) {
  40. TSVideoOperator.shared.playerViewModel.currentVideo = lastVideo
  41. TSVideoOperator.shared.playerViewModel.currentVideos = TSVideoOperator.shared.dataManager.fetchCachedVideos()
  42. PlayerManager.shared.miniBar.updateVideoInfo(video: lastVideo, state: .pause)
  43. }
  44. if let loopMode = UserDefaults.standard.string(forKey: "lastedPlayMode") {
  45. let mMode = LoopMode(rawValue: loopMode) ?? .cyclic
  46. TSVideoOperator.shared.playerViewModel.loopMode = mMode
  47. }
  48. }
  49. @objc func recordData() {
  50. if UserDefaults.standard.value(forKey: "CachedTag") == nil {
  51. UserDefaults.standard.setValue("1", forKey: "CachedTag")
  52. SKStoreReviewController.requestReview()
  53. }
  54. }
  55. func downloadNotifaction() {
  56. NotificationCenter.default.addObserver(self, selector: #selector(recordData), name: kGroupDownloadFinishNotifactionName, object: nil)
  57. }
  58. static func requestAdTrack() {
  59. DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
  60. ATTrackingManager.requestTrackingAuthorization(completionHandler: { status in
  61. // 这里可以处理用户的选择
  62. switch status {
  63. case .authorized:
  64. print("授权成功,可以开始跟踪")
  65. case .denied:
  66. print("用户拒绝了授权")
  67. case .restricted:
  68. print("该设备的用户无法授权")
  69. case .notDetermined:
  70. print("用户尚未做出选择")
  71. @unknown default:
  72. print("未知状态")
  73. }
  74. })
  75. }
  76. }
  77. func applicationDidBecomeActive(_ application: UIApplication) {
  78. AppDelegate.requestAdTrack()
  79. }
  80. func applicationWillTerminate(_ application: UIApplication) {
  81. UserDefaults.standard.setValue(PlayerManager.shared.currentVideo?.videoId ?? "", forKey: "lastedVideoId")
  82. UserDefaults.standard.setValue(PlayerManager.shared.currentLoopMode.rawValue, forKey: "lastedPlayMode")
  83. }
  84. func applicationWillEnterForeground(_ application: UIApplication) {
  85. // 热启动显示开屏广告
  86. if let topVC = UIApplication.defaultViewController?.topVc {
  87. if PurchaseManager.default.isVip {
  88. return
  89. }
  90. DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
  91. ADManager.shared.showLaunchAdWhenActive(scene: ADScene.launch, from: topVC)
  92. }
  93. }
  94. }
  95. }
  96. extension AppDelegate {
  97. func initPlatform() {
  98. TSColorConfigShared.naviMianTextColor = .white
  99. }
  100. }