AppDelegate.swift 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // AppDelegate.swift
  3. // VenusKitto
  4. //
  5. // Created by Neoa on 2025/8/21.
  6. //
  7. import UIKit
  8. import AnyThinkSDK
  9. import AppTrackingTransparency
  10. import AdSupport
  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. DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
  16. self.requestTrackingPermission()
  17. }
  18. self.initAnythinkSDK()
  19. return true
  20. }
  21. // MARK: UISceneSession Lifecycle
  22. func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
  23. // Called when a new scene session is being created.
  24. // Use this method to select a configuration to create the new scene with.
  25. return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
  26. }
  27. func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
  28. // Called when the user discards a scene session.
  29. // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
  30. // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
  31. }
  32. func initAnythinkSDK() {
  33. ATAPI.setLogEnabled(false)
  34. ATAPI.integrationChecking()
  35. // 初始化 AnyThink
  36. do {
  37. let ok: () = try ATAPI.sharedInstance().start(withAppID: kTakuAppID, appKey: kTakuAppKey)
  38. print("AnyThink SDK start success: \(ok)")
  39. } catch {
  40. print("AnyThink SDK start failed:", error)
  41. }
  42. }
  43. func requestTrackingPermission() {
  44. if #available(iOS 14, *) {
  45. ATTrackingManager.requestTrackingAuthorization { status in
  46. switch status {
  47. case .authorized:
  48. print("Authorized to track.")
  49. // Access IDFA (if needed)
  50. case .denied:
  51. print("Denied tracking permission.")
  52. case .notDetermined:
  53. print("Tracking permission not determined.")
  54. case .restricted:
  55. print("Tracking permission restricted.")
  56. @unknown default:
  57. print("Unknown tracking status.")
  58. }
  59. }
  60. } else {
  61. // Handle older iOS versions if necessary
  62. print("App Tracking Transparency not available on this iOS version.")
  63. }
  64. }
  65. }