fix not
This commit is contained in:
parent
4226476d3a
commit
3d4ca58912
@ -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 {
|
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
|
||||||
registerForPushNotifications()
|
registerForPushNotifications()
|
||||||
@ -123,6 +123,41 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
|||||||
completionHandler(.newData)
|
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]) {
|
private func handleRemoteNotification(userInfo: [AnyHashable: Any]) {
|
||||||
print("收到远程通知: \(userInfo)")
|
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) {
|
private func handleDeepLink(_ link: String) {
|
||||||
// 实现深度链接处理逻辑
|
// 实现深度链接处理逻辑
|
||||||
print("处理深度链接: \(link)")
|
print("处理深度链接: \(link)")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user