iOS10、Swift 3 和 FCM 委托(delegate)错误

标签 ios swift firebase firebase-cloud-messaging

我遇到错误:

"Value of type FIRMessaging has no member 'remoteMessageDelegate'" on FIRMessaging.messaging().remoteMessageDelegate = self

我从 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()
    }

最佳答案

我遇到了同样的问题。看来谷歌文档已经过时了,我看了一下Cocoapods Firebase Messaging page我解决了在终端内更新 cocoapods 仓库的问题:

pod repo update

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

pod 'Firebase/Core'
pod 'Firebase/Messaging'

与:

 pod 'Firebase', '~> 3.7'
 pod 'FirebaseMessaging', '~> 1.2'
 pod 'FirebaseAnalytics', '~> 3.3'

这将下载 FirebaseMessaging 1.2 而不是 1.1

关于iOS10、Swift 3 和 FCM 委托(delegate)错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39753105/

相关文章:

ios - CALayer - 将子层放在 Storyboard UIButtons 下方?

ios - 无法使用 Swift 读取 Firebase 数据

ios - 在太空入侵者中生成 Sprite

android - Firebase isSuccessful() 总是返回 false

xcode - Firebase 提供商数据

ios - NSTimezone 从 timezoneId 获取缩写

ios - AudioQueue 修剪和缓冲区大小

ios - 为什么我的代码没有删除字符串的空格?

ios - 在 Swift 语言中也获取数组中的键值及其在另一个数组中的值

android - 更新 Firebase Recyclerview 适配器不会删除以前的列表