Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift AppDeligate does not conform to protocol 'MessagingDelegate'

Using Swift2.3 and Xcode 8
I upgraded Firebase to version 4

I followed all mentioned Changes in the new version https://firebase.google.com/docs/reference/ios/naming-migration-guide#changes_in_the_new_version

Stil I get one error saying

Type 'AppDelegate' does not conform to protocol 'MessagingDelegate'

I dono what this method is changed to or which new method I need to add. kindly help me

class Appdelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, MessagingDelegate
{
    func application(remoteMessage: MessagingRemoteMessage)
    {
        let remoteMsgVar = remoteMessage.appData
        print("remoteMessage : ", remoteMsgVar)
    }
}
like image 712
Sujay U N Avatar asked Feb 06 '26 17:02

Sujay U N


1 Answers

In order to conform to the MessagingDelegate protocol, you must include the functions:

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)

}

For future reference, Xcode 8 will show you which functions are required in the protocol under errors:

rom

For anyone using Xcode 9, you can add the protocol stubs right from the error message.

AppDelegate

like image 192
Jen Person Avatar answered Feb 09 '26 05:02

Jen Person