"消息"类型的值没有成员"remoteMessageDelegate"

fel*_*lon 8 firebase swift

当我更新firebase pods时出现以下错误:

"消息"类型的值没有成员"remoteMessageDelegate"

 //notification

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

        // For iOS 10 display notification (sent via APNS)
        UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
        // For iOS 10 data message (sent via FCM)
        Messaging.messaging().remoteMessageDelegate = self as? MessagingDelegate

    }
Run Code Online (Sandbox Code Playgroud)

我怎么能解决这个问题?

Hab*_*lil 7

if #available(iOS 10.0, *) {
// For iOS 10 display notification (sent via APNS)
 UNUserNotificationCenter.current().delegate = self

 let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
  UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: {_, _ in })
} else {
  let settings: UIUserNotificationSettings =
 UIUserNotificationSettings(types: [.alert, .badge, .sound], 
categories: nil)
application.registerUserNotificationSettings(settings)
}

application.registerForRemoteNotifications()
Run Code Online (Sandbox Code Playgroud)

https://github.com/firebase/quickstart-ios/blob/dc2cd2db6e82e5c475fa3f0efe75df8b54f04544/messaging/MessagingExampleSwift/AppDelegate.swift#L40-L55

  • 答案是不正确的.`Messaging.messaging().remoteMessageDelegate`已被移动到`Messaging.messaging().delegate`.上面的代码片段错过了作为原始问题的实际修复的行. (8认同)