在FIRMessagingDelegate类的扩展中,引发了一个错误:

使用未声明的类型'FIRMessagingDelegate'

此外,此错误会在didFinishLaunchinWithOptions方法中引发:

类型“FIRMessaging”的值没有成员“remoteMessageDelegate”

import UIKit
import Firebase
import UserNotifications
import FirebaseMessaging
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    override init() {
        FIRApp.configure() //this is the updated version.
    }


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        //FIRApp.configure()

        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
            // For iOS 10 data message (sent via FCM)
            FIRMessaging.messaging().remoteMessageDelegate = self
        }

        application.registerForRemoteNotifications() // ERROR:  Value of type 'FIRMessaging' has no member 'remoteMessageDelegate'

        return true
    }

    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
                     fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        // If you are receiving a notification message while your app is in the background,
        // this callback will not be fired till the user taps on the notification launching the application.
        // TODO: Handle data of notification

        // Print message ID.
        print("Message ID: \(userInfo["gcm.message_id"]!)")

        // Print full message.
        print(userInfo)
    }

    func tokenRefreshNotification() {
        let fcmDeviceToken = FIRInstanceID.instanceID().token()
        // TODO: Send token to server
    }
}


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

    // Receive displayed notifications for iOS 10 devices.

    func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        let userInfo = notification.request.content.userInfo
        // Print message ID.
        print("Message ID: \(userInfo["gcm.message_id"]!)")

        // Print full message.
        print("%@", userInfo)
    }
}

extension AppDelegate : FIRMessagingDelegate { // ERROR: Use of undeclared type 'FIRMessagingDelegate'
    // Receive data message on iOS 10 devices.
    func applicationReceivedRemoteMessage(_ remoteMessage: FIRMessagingRemoteMessage) { // ERROR: Use of undeclared type 'FIRMessagingRemoteMessage'
        print("%@", remoteMessage.appData)
    }
}

最佳答案

请尝试运行pod update,这对于这些人来说是一个可行的解决方案-> https://github.com/firebase/quickstart-ios/issues/107

07-24 09:36