Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS10, Swift 3, and FCM delegate error

I'm getting error:

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

I get this snippet code from FCM setup guide:

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()
    }
like image 417
Nic Chong Avatar asked Sep 28 '16 16:09

Nic Chong


2 Answers

I had the same problem. It seems that Google documentation is out to date, I took a look Cocoapods Firebase Messaging page and I solved updating the cocoapods repo doing inside the Terminal:

pod repo update

And then replacing the following lines in my Podfile:

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

With:

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

This will download FirebaseMessaging 1.2 instead of 1.1

like image 198
andrew_b Avatar answered Oct 27 '22 17:10

andrew_b


Run in the console:

pod update
like image 25
Wilson Avatar answered Oct 27 '22 15:10

Wilson