SwiftUI将使用选项完成LaunchingWithOptions具有launchOptions=nil

SwiftUI将使用选项完成LaunchingWithOptions具有launchOptions=nil,swiftui,firebase-cloud-messaging,ios14,Swiftui,Firebase Cloud Messaging,Ios14,我已经为Firebase通知注册了应用程序,并且我已经实现了UNUserNotificationCenterDelegate。当应用程序正在运行或在后台运行时,将调用didReceive方法 当我终止应用程序并发送通知时。调用了willFinishLaunchingWithOptions和didFinishLaunchingWithOptions方法,但launchOptions对象为nil,不包含任何.remoteNotification键 if launchOptions != nil {

我已经为Firebase通知注册了应用程序,并且我已经实现了
UNUserNotificationCenterDelegate
。当应用程序正在运行或在后台运行时,将调用
didReceive
方法

当我终止应用程序并发送通知时。调用了
willFinishLaunchingWithOptions
didFinishLaunchingWithOptions
方法,但launchOptions对象为nil,不包含任何.remoteNotification键

if launchOptions != nil {
            logger.log("There is stuff in launch options")
        }
我的AppDelegate设置


@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate 

@available(iOS 10, *)
extension AppDelegate: UNUserNotificationCenterDelegate 

extension AppDelegate: MessagingDelegate

上述代码从不向控制台打印任何日志消息

我已经尝试了所有的方法和谷歌,但是没有具体的方法

我使用的是iOS 14 beta 6和Xcode beta 6


提前感谢。

您可以通过
连接选项从SceneDelegate not AppDelegate获得通知。notificationResponse

从 &

[更新] 即使应用程序未启动,您也可以从
userNotificationCenter
获得通知

func userNotificationCenter(_ center: UNUserNotificationCenter,
                                didReceive response: UNNotificationResponse,
                                withCompletionHandler completionHandler: @escaping () -> Void) {
        print("open notification")
        let userInfo = response.notification.request.content.userInfo
        
        print(userInfo)
        completionHandler()
    }

它不应该在那里。您能告诉我如何/在哪里设置代理吗?(顺便说一句,此工作流应该在设备上测试-它在模拟器上不工作)。是的,我在真实设备上测试,而不是在模拟器上测试。@Asperi这是我的AppDelegate,用我的AppDelegate设置更新了问题
func userNotificationCenter(_ center: UNUserNotificationCenter,
                                didReceive response: UNNotificationResponse,
                                withCompletionHandler completionHandler: @escaping () -> Void) {
        print("open notification")
        let userInfo = response.notification.request.content.userInfo
        
        print(userInfo)
        completionHandler()
    }