【问题标题】:iOS10, Swift 3, and FCM delegate erroriOS10、Swift 3 和 FCM 委托错误
【发布时间】:2016-09-28 16:35:49
【问题描述】:

我收到错误:

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

我从 FCM 设置指南中获得了这个 sn-p 代码:

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

【问题讨论】:

    标签: ios swift firebase firebase-cloud-messaging


    【解决方案1】:

    我遇到了同样的问题。谷歌文档似乎已经过时了,我看了一下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

    【讨论】:

    • 我已经解决了一个与 FIRMessagingDelegate 相关的问题大约 5 个小时了,它不允许我将代理分配给 AppDelegate.swift 文件,解决的方法是设置特定版本的带有 pod 'FirebaseMessaging', '~> 1.2' 的 pod 非常感谢!!
    【解决方案2】:

    在控制台中运行:

    pod update
    

    【讨论】:

      【解决方案3】:

      你需要更新你的 cocoapod 版本

      尝试从终端应用程序将 cocoapod 的版本更新到最新版本

      sudo gem update
      

      更新到最新的 cocoapod 后更新你的 pods

      pod update
      

      【讨论】:

      • 这对我有用!执行 pod update 时请耐心等待。我花了超过 5 分钟。
      【解决方案4】:

      如果您不想更新所有 pod,您可以只更新那些 Firebase pod

      从 CocoaPods 1.0 开始,默认情况下,“pod install”不会发生“pod repo udpate”

      pod update 'Firebase/Core'
      pod update 'Firebase/Database'
      pod update 'Firebase/Auth'
      pod update 'Firebase/Messaging'
      

      【讨论】:

        【解决方案5】:

        所以你需要从 podfile 中删除行:

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

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

        【讨论】:

          猜你喜欢
          • 2017-02-05
          • 1970-01-01
          • 1970-01-01
          • 2017-05-05
          • 2017-06-07
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多