【问题标题】:Swift AppDeligate does not conform to protocol 'MessagingDelegate'Swift AppDeligate 不符合协议'MessagingDelegate'
【发布时间】:2018-01-23 23:37:01
【问题描述】:

使用 Swift2.3 和 Xcode 8
我将 Firebase 升级到版本 4

我遵循了新版本中所有提到的更改 https://firebase.google.com/docs/reference/ios/naming-migration-guide#changes_in_the_new_version

我仍然收到一个错误提示

类型“AppDelegate”不符合协议“MessagingDelegate”

我不知道此方法更改为什么或需要添加哪个新方法。 请帮助我

class Appdelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, MessagingDelegate
{
    func application(remoteMessage: MessagingRemoteMessage)
    {
        let remoteMsgVar = remoteMessage.appData
        print("remoteMessage : ", remoteMsgVar)
    }
}

【问题讨论】:

    标签: ios swift firebase protocols appdelegate


    【解决方案1】:

    为了符合MessagingDelegate协议,必须包含以下函数:

    func messaging(messaging: Messaging, didRefreshRegistrationToken fcmToken: String)
    {
    
    }
    
    /// This method is called on iOS 10 devices to handle data messages received via FCM through its
    /// direct channel (not via APNS). For iOS 9 and below, the FCM data message is delivered via the
    /// UIApplicationDelegate's -application:didReceiveRemoteNotification: method.
    @available(iOS 10.0, *)
    func messaging(messaging: Messaging, didReceive remoteMessage: MessagingRemoteMessage)
    {
        let FcmRcdNfnNryVal = remoteMessage.appData
        print("iOS 10.0 FcmRcdRmtNfnMsg : ", FcmRcdNfnNryVal)
    
    }
    

    为了将来参考,Xcode 8 会在错误下显示协议中需要哪些函数:

    对于使用 Xcode 9 的任何人,您可以直接从错误消息中添加协议存根。

    【讨论】:

    • 感谢您的提示。我们必须在新版本中包含两种新方法并更新您的答案
    • 你也可以考虑为我的问题投票吗?所以它会出现并帮助像我一样面临问题的其他人
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-10
    相关资源
    最近更新 更多