This commit is contained in:
anlicheng 2025-04-03 16:48:18 +08:00
parent 4226476d3a
commit 3d4ca58912

View File

@ -51,7 +51,7 @@ struct dimensionhubApp: App {
}
class AppDelegate: UIResponder, UIApplicationDelegate {
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
registerForPushNotifications()
@ -123,6 +123,41 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
completionHandler(.newData)
}
// MARK: UNUserNotificationCenterDelegate
// App
func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
let userInfo = notification.request.content.userInfo
//
handleRemoteNotification(userInfo: userInfo)
//
completionHandler([.banner, .sound])
}
//
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
//
handleRemoteNotification(userInfo: userInfo)
//
if let deepLink = userInfo["deepLink"] as? String {
handleDeepLink(deepLink)
}
completionHandler()
}
// MARK:
private func handleRemoteNotification(userInfo: [AnyHashable: Any]) {
print("收到远程通知: \(userInfo)")
@ -139,41 +174,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
}
}
//
extension AppDelegate: UNUserNotificationCenterDelegate {
// App
func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
let userInfo = notification.request.content.userInfo
//
handleRemoteNotification(userInfo: userInfo)
//
completionHandler([.banner, .sound])
}
//
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
//
handleRemoteNotification(userInfo: userInfo)
//
if let deepLink = userInfo["deepLink"] as? String {
handleDeepLink(deepLink)
}
completionHandler()
}
private func handleDeepLink(_ link: String) {
//
print("处理深度链接: \(link)")