|
@@ -13,11 +13,11 @@ import AppTrackingTransparency |
|
@@ -13,11 +13,11 @@ import AppTrackingTransparency |
|
13
|
import AdSupport
|
13
|
import AdSupport
|
|
14
|
|
14
|
|
|
15
|
@Observable
|
15
|
@Observable
|
|
16
|
-class AppDelegate: FlutterAppDelegate {
|
16
|
+class AppDelegate: NSObject, UIApplicationDelegate {
|
|
17
|
|
17
|
|
|
18
|
let flutterEngine: FlutterEngine = FlutterEngine(name: "main_flutter_engine")
|
18
|
let flutterEngine: FlutterEngine = FlutterEngine(name: "main_flutter_engine")
|
|
19
|
|
19
|
|
|
20
|
- override func application(
|
20
|
+ func application(
|
|
21
|
_ application: UIApplication,
|
21
|
_ application: UIApplication,
|
|
22
|
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
|
22
|
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
|
|
23
|
) -> Bool {
|
23
|
) -> Bool {
|
|
@@ -32,11 +32,11 @@ class AppDelegate: FlutterAppDelegate { |
|
@@ -32,11 +32,11 @@ class AppDelegate: FlutterAppDelegate { |
|
32
|
NativePigeonRegistrar.register(binaryMessenger: flutterEngine.binaryMessenger)
|
32
|
NativePigeonRegistrar.register(binaryMessenger: flutterEngine.binaryMessenger)
|
|
33
|
WatchConnectivityService.shared.activate()
|
33
|
WatchConnectivityService.shared.activate()
|
|
34
|
HealthKitService.shared.startBackgroundObserversIfNeeded()
|
34
|
HealthKitService.shared.startBackgroundObserversIfNeeded()
|
|
35
|
-
|
|
|
|
36
|
- return super.application(application, didFinishLaunchingWithOptions: launchOptions)
|
35
|
+//
|
|
|
|
36
|
+ return true
|
|
37
|
}
|
37
|
}
|
|
38
|
|
38
|
|
|
39
|
- override func application(_ application: UIApplication,
|
39
|
+ func application(_ application: UIApplication,
|
|
40
|
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
|
40
|
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
|
|
41
|
let tokenParts = deviceToken.map { data in String(format: "%02.2hhx", data) }
|
41
|
let tokenParts = deviceToken.map { data in String(format: "%02.2hhx", data) }
|
|
42
|
let token = tokenParts.joined()
|
42
|
let token = tokenParts.joined()
|
|
@@ -44,18 +44,20 @@ class AppDelegate: FlutterAppDelegate { |
|
@@ -44,18 +44,20 @@ class AppDelegate: FlutterAppDelegate { |
|
44
|
print("✅ Device Token: \(token)")
|
44
|
print("✅ Device Token: \(token)")
|
|
45
|
}
|
45
|
}
|
|
46
|
|
46
|
|
|
47
|
- override func application(_ application: UIApplication,
|
47
|
+ func application(_ application: UIApplication,
|
|
48
|
didFailToRegisterForRemoteNotificationsWithError error: Error) {
|
48
|
didFailToRegisterForRemoteNotificationsWithError error: Error) {
|
|
49
|
print("❌ Failed to register: \(error.localizedDescription)")
|
49
|
print("❌ Failed to register: \(error.localizedDescription)")
|
|
50
|
}
|
50
|
}
|
|
51
|
-
|
|
|
|
52
|
- override func userNotificationCenter(_ center: UNUserNotificationCenter,
|
51
|
+}
|
|
|
|
52
|
+
|
|
|
|
53
|
+extension AppDelegate: UNUserNotificationCenterDelegate{
|
|
|
|
54
|
+ func userNotificationCenter(_ center: UNUserNotificationCenter,
|
|
53
|
willPresent notification: UNNotification,
|
55
|
willPresent notification: UNNotification,
|
|
54
|
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
|
56
|
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
|
|
55
|
completionHandler([.banner, .sound, .badge])
|
57
|
completionHandler([.banner, .sound, .badge])
|
|
56
|
}
|
58
|
}
|
|
57
|
|
59
|
|
|
58
|
- override func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
|
60
|
+ func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
|
|
59
|
let userInfo = response.notification.request.content.userInfo
|
61
|
let userInfo = response.notification.request.content.userInfo
|
|
60
|
|
62
|
|
|
61
|
// 从通知中获取 URL
|
63
|
// 从通知中获取 URL
|
|
@@ -76,7 +78,6 @@ class AppDelegate: FlutterAppDelegate { |
|
@@ -76,7 +78,6 @@ class AppDelegate: FlutterAppDelegate { |
|
76
|
}
|
78
|
}
|
|
77
|
}
|
79
|
}
|
|
78
|
|
80
|
|
|
79
|
-
|
|
|
|
80
|
extension AppDelegate {
|
81
|
extension AppDelegate {
|
|
81
|
private func requestIDFAAuthorization() {
|
82
|
private func requestIDFAAuthorization() {
|
|
82
|
if ATTrackingManager.trackingAuthorizationStatus == .notDetermined {
|
83
|
if ATTrackingManager.trackingAuthorizationStatus == .notDetermined {
|