iOS10,Swift 3和FCM委托错误

Nic*_*ong 5 ios firebase swift firebase-cloud-messaging

我收到错误:

"Value of type FIRMessaging has no member 'remoteMessageDelegate'" on FIRMessaging.messaging().remoteMessageDelegate = self
Run Code Online (Sandbox Code Playgroud)

我从FCM设置指南中获取此代码段:

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

    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 //Get error on this line

    } else {
        let settings: UIUserNotificationSettings =
            UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
        application.registerUserNotificationSettings(settings)
        application.registerForRemoteNotifications()
    }
Run Code Online (Sandbox Code Playgroud)

小智 5

我有同样的问题.似乎Google文档是最新的,我看了一下Cocoapods Firebase Messaging页面,我解决了在终端内部更新cocoapods repo:

pod repo update
Run Code Online (Sandbox Code Playgroud)

然后替换我的Podfile中的以下行:

pod 'Firebase/Core'
pod 'Firebase/Messaging'
Run Code Online (Sandbox Code Playgroud)

附:

 pod 'Firebase', '~> 3.7'
 pod 'FirebaseMessaging', '~> 1.2'
 pod 'FirebaseAnalytics', '~> 3.3'
Run Code Online (Sandbox Code Playgroud)

这将下载FirebaseMessaging 1.2而不是1.1


小智 -1

因此,您需要从 podfile 中删除以下行:

pod 'Firebase/Core'
pod 'Firebase/Messaging'
Run Code Online (Sandbox Code Playgroud)

然后安装 pod,再次添加这些行并再次安装。这为我解决了这个问题。