小编Sil*_*viu的帖子

SwiftUI - 当用户打开推送通知时打开特定视图

A 有一个用 SwiftUI 制作的应用程序,使用 Parse 作为数据库。我在应用程序的某些部分集成了一些发送通知的云功能(例如:当有人向您发送消息时,您将收到由该云功能触发的推送通知)。在过去的几天里,我一直在努力寻找当您按通知打开应用程序时如何打开特定视图。我找到了一些解决方案,但无法使它们发挥作用。

这是我到目前为止的代码:

class AppDelegate: NSObject, UIApplicationDelegate, UNUserNotificationCenterDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
        
        //Parse Intialization
        ...
        //notifications
        registerForPushNotifications()
        //Notification Badge
        UIApplication.shared.applicationIconBadgeNumber = 0
        // start notification while app is in Foreground
        UNUserNotificationCenter.current().delegate = self
        return true
    }
    
    // This function will be called right after user tap on the notification
    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
        print("app opened …
Run Code Online (Sandbox Code Playgroud)

push-notification apple-push-notifications swiftui

14
推荐指数
1
解决办法
9734
查看次数