AppDelegate.swift 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. downloadNotifaction()
  23. return true
  24. }
  25. func goToTab() {
  26. window?.rootViewController = TSTabBarController()
  27. }
  28. func goToLoadVC() {
  29. _ = TSImageDataCenter.shared
  30. window?.rootViewController = TSLaunchVC()
  31. }
  32. func initBaseDatas() {
  33. var config = TSConfiguration.default
  34. config.configurePath = "http://p.100yearslater.com/live/config"
  35. TSVideoOperator.shared.loadWithConfiguration(config: config, needJs: true)
  36. if let videoId = UserDefaults.standard.string(forKey: "lastedVideoId"),
  37. !videoId.isEmpty,
  38. let lastVideo = TSVideoOperator.shared.dataManager.fetchVideo(videoId: videoId) {
  39. TSVideoOperator.shared.playerViewModel.currentVideo = lastVideo
  40. TSVideoOperator.shared.playerViewModel.currentVideos = TSVideoOperator.shared.dataManager.fetchCachedVideos()
  41. PlayerManager.shared.miniBar.updateVideoInfo(video: lastVideo, state: .pause)
  42. }
  43. if let loopMode = UserDefaults.standard.string(forKey: "lastedPlayMode") {
  44. let mMode = LoopMode(rawValue: loopMode) ?? .cyclic
  45. TSVideoOperator.shared.playerViewModel.loopMode = mMode
  46. }
  47. }
  48. @objc func recordData() {
  49. if UserDefaults.standard.value(forKey: "CachedTag") == nil {
  50. UserDefaults.standard.setValue("1", forKey: "CachedTag")
  51. SKStoreReviewController.requestReview()
  52. }
  53. }
  54. func downloadNotifaction() {
  55. NotificationCenter.default.addObserver(self, selector: #selector(recordData), name: kGroupDownloadFinishNotifactionName, object: nil)
  56. }
  57. static func requestAdTrack() {
  58. DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
  59. ATTrackingManager.requestTrackingAuthorization(completionHandler: { status in
  60. // 这里可以处理用户的选择
  61. switch status {
  62. case .authorized:
  63. print("授权成功,可以开始跟踪")
  64. case .denied:
  65. print("用户拒绝了授权")
  66. case .restricted:
  67. print("该设备的用户无法授权")
  68. case .notDetermined:
  69. print("用户尚未做出选择")
  70. @unknown default:
  71. print("未知状态")
  72. }
  73. })
  74. }
  75. }
  76. func applicationDidBecomeActive(_ application: UIApplication) {
  77. AppDelegate.requestAdTrack()
  78. }
  79. func applicationWillTerminate(_ application: UIApplication) {
  80. UserDefaults.standard.setValue(PlayerManager.shared.currentVideo?.videoId ?? "", forKey: "lastedVideoId")
  81. UserDefaults.standard.setValue(PlayerManager.shared.currentLoopMode.rawValue, forKey: "lastedPlayMode")
  82. }
  83. func applicationWillEnterForeground(_ application: UIApplication) {
  84. // 热启动显示开屏广告
  85. if let topVC = UIApplication.defaultViewController?.topVc {
  86. if PurchaseManager.default.isVip {
  87. return
  88. }
  89. DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
  90. ADManager.shared.showLaunchAdWhenActive(scene: ADScene.launch, from: topVC)
  91. }
  92. }
  93. }
  94. }
  95. extension AppDelegate {
  96. }