3

我正在尝试使用 Firebase 在我的应用程序中实现推送通知,但是在遵循他们的文档时,我必须添加以下代码行:

        if #available(iOS 10.0, *) {
        let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
        UNUserNotificationCenter.current().requestAuthorization(options: authOptions, completionHandler: {_, _ in})

        UNUserNotificationCenter.current().delegate = self
        FIRMessaging.messaging().remoteMessageDelegate = self
    } else {
        let settings: UIUserNotificationSettings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
        application.registerUserNotificationSettings(settings)
    }

添加此代码后,应用程序将无法编译,它会向我抛出错误,让我知道我

无法将类型的值分配AppDelegate给类型 FirMessagingDelegate

而我

无法将 AppDelegate 类型的值分配给 UNUserNotificationCenterDelegate 类型。

所以很自然地,我将FIRMessagingDelegateand添加UNUserNotificationCenterDelegate到我的应用程序中,但是FIRMessagingDelegate不允许应用程序编译说

类型 AppDelegate 不符合协议“FirMessagingDelegate”。

Any ideas? I haven't managed to find any other situations in which others have encountered this error, and in Google's documentation, these two delegates aren't even added.

4

1 回答 1

7

You are on the right track, 1 more thing to do is making your AppDelegate class conform to the 'FirMessagingDelegate' protocol, by implementing the applicationReceivedRemoteMessage function somewhere is your AppDelegate class as it is required by the 'FirMessagingDelegate' protocol described here Firebase Doc

于 2016-12-31T13:17:03.247 回答