4

I'm working with some Swift and FCM code and after updating pods I'm getting two errors. I have done research but can't figure out what to do to fix it.

Here is the code:

// For iOS 10 display notification (sent via APNS)
[UNUserNotificationCenter currentNotificationCenter].delegate = self;
// For iOS 10 data message (sent via FCM)
[FIRMessaging messaging].remoteMessageDelegate = self;

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    [[FIRInstanceID instanceID] setAPNSToken:deviceToken type:FIRInstanceIDAPNSTokenTypeProd]; error message———> No visible @interface for 'FIRInstanceID' declares the selector 'setAPNSToken:type:'<--error message ends  

    NSLog(@"deviceToken1 = %@; %@",deviceToken,[[FIRInstanceID instanceID] token]);
}

Here is the error message:

Property 'remoteMessageDelegate' not found on object of type 'FIRMessaging *'

KENdi
  • 7,576
  • 2
  • 16
  • 31

1 Answers1

6

In version 5.0.0, they removed remoteMessageDelegate and replaced it with delegate:
https://firebase.google.com/support/release-notes/ios#5.0.0
release notes 5.0.0

It is also delegate now in the current FIRMessaging API documentation: https://firebase.google.com/docs/reference/ios/firebasemessaging/api/reference/Classes/FIRMessaging#/c:objc(cs)FIRMessaging(py)delegate

Delegate to handle FCM token refreshes, and remote data messages received via FCM direct channel.

@property (readwrite, nonatomic, nullable) id<FIRMessagingDelegate> delegate;

You can refer to their quickstart-ios code for sample usage:
https://github.com/firebase/quickstart-ios/blob/master/messaging/MessagingExample/AppDelegate.m#L36

  // [START set_messaging_delegate]
  [FIRMessaging messaging].delegate = self;
  // [END set_messaging_delegate]
Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
  • Yep that fixed remoteMessageDelegate all I have left to fix is [[FIRInstanceID instanceID] setAPNSToken:deviceToken type:FIRInstanceIDAPNSTokenTypeProd]; which is giving me this error No visible @interface for 'FIRInstanceID' declares the selector 'setAPNSToken:type:' –  Jan 31 '19 at 23:52
  • You need to learn to read the API docs. From the release notes I linked to in my answer, they moved `setAPNSToken:type` from `FIRInstanceID` to `FIRMessaging`. If you go to the [FIRInstanceID API docs](https://firebase.google.com/docs/reference/ios/firebaseinstanceid/api/reference/Classes/FIRInstanceID), there is no more `setAPNSToken`. It is now indeed part of [FIRMessaging](https://firebase.google.com/docs/reference/ios/firebasemessaging/api/reference/Classes/FIRMessaging#-setapnstokentype). It looks like you're using "old" FCM code, because a lot has changed in the current versions. – Gino Mempin Feb 01 '19 at 00:06
  • 1
    Thanks for the advice I'll be on it ASAP. –  Feb 01 '19 at 00:15