React-native-fcm: No known class method for RNFIRMessaging selectors

Created on 3 Feb 2017  路  7Comments  路  Source: evollu/react-native-fcm

React Native version: "0.40.0"
React-native-fcm version: "4.0.0"

Device: iphone7 simulator (not running)

I have followed the instructions and copied the code from the examples and README, but in my AppDelegate.m file I get these errors on build:

  1. no known class method for selector 'willPresentNotification:withCompletionHandler:'
  2. no known class method for selector 'didReceiveNotificationResponse:withCompletionHandler:'
  3. no known class method for selector 'didReceiveLocalNotification:'
  4. no known class method for selector 'didReceiveRemoteNotification:fetchCompletionHandler:'

I have tried both the cocoapods and the non-cocoapods installation approach with no luck. What could be the problem here?

Picture attached.
screen shot 2017-02-02 at 10 20 18 pm

Most helpful comment

@ivankennethwang I looked into the docs of the previous versions, since I was using RN 0.35 and, thus, version 2.5.x of this lib. There, on the readme.md, were the correct methods to use on that particular version on AppDelegate.m. Quoting:

Edit AppDelegate.m:

+ #import "RNFIRMessaging.h"
  //...

  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  {
  //...
+   [FIRApp configure];
+   [[UNUserNotificationCenter currentNotificationCenter] setDelegate:self];
+ }
+
+ - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
+ {
+   [[NSNotificationCenter defaultCenter] postNotificationName:FCMNotificationReceived object:self userInfo:notification.request.content.userInfo];
+     if([[notification.request.content.userInfo valueForKey:@"show_in_foreground"] isEqual:@YES]){
+     completionHandler(UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionSound);
+   }else{
+     completionHandler(UNNotificationPresentationOptionNone);
+   }
+
+ }
+
+ - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler
+ {
+     NSDictionary* userInfo = [[NSMutableDictionary alloc] initWithDictionary: response.notification.request.content.userInfo];
+   [userInfo setValue:@YES forKey:@"opened_from_tray"];
+   [[NSNotificationCenter defaultCenter] postNotificationName:FCMNotificationReceived object:self userInfo:userInfo];
+ }
+
+ //You can skip this method if you don't want to use local notification
+ -(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
+   [[NSNotificationCenter defaultCenter] postNotificationName:FCMNotificationReceived object:self userInfo:notification.userInfo];
+ }
+
+ - (void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler{
+   [[NSNotificationCenter defaultCenter] postNotificationName:FCMNotificationReceived object:self userInfo:userInfo];
+   completionHandler(UIBackgroundFetchResultNoData);
+ }

All 7 comments

@jdmcpeek what did you do to solve this? It's happening to me too. I've just update FirebaseCore, could it be related?

@fplgusmao I updated react-native-fcm to a later version, 6.0.2. It wasn't clear to do so in the docs, but that's the version the author used in the example code, along with RN 0.40.0.

Try react-native unlink react-native-fcm, then npm i -S [email protected]. Then relink with react-native link react-native-fcm

Thanks a lot! my problem was related to that. In my case, however, I was using a lower version of React-native, so I had to use the 2.6.x version of this lib. That older version doesn't have those methods defined, so I had to dive into the Readme's to find how to correctly setup the notifications.

@fplgusmao can you share how you fixed it?

@ivankennethwang I looked into the docs of the previous versions, since I was using RN 0.35 and, thus, version 2.5.x of this lib. There, on the readme.md, were the correct methods to use on that particular version on AppDelegate.m. Quoting:

Edit AppDelegate.m:

+ #import "RNFIRMessaging.h"
  //...

  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  {
  //...
+   [FIRApp configure];
+   [[UNUserNotificationCenter currentNotificationCenter] setDelegate:self];
+ }
+
+ - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
+ {
+   [[NSNotificationCenter defaultCenter] postNotificationName:FCMNotificationReceived object:self userInfo:notification.request.content.userInfo];
+     if([[notification.request.content.userInfo valueForKey:@"show_in_foreground"] isEqual:@YES]){
+     completionHandler(UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionSound);
+   }else{
+     completionHandler(UNNotificationPresentationOptionNone);
+   }
+
+ }
+
+ - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler
+ {
+     NSDictionary* userInfo = [[NSMutableDictionary alloc] initWithDictionary: response.notification.request.content.userInfo];
+   [userInfo setValue:@YES forKey:@"opened_from_tray"];
+   [[NSNotificationCenter defaultCenter] postNotificationName:FCMNotificationReceived object:self userInfo:userInfo];
+ }
+
+ //You can skip this method if you don't want to use local notification
+ -(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
+   [[NSNotificationCenter defaultCenter] postNotificationName:FCMNotificationReceived object:self userInfo:notification.userInfo];
+ }
+
+ - (void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler{
+   [[NSNotificationCenter defaultCenter] postNotificationName:FCMNotificationReceived object:self userInfo:userInfo];
+   completionHandler(UIBackgroundFetchResultNoData);
+ }

Thanks @fplgusmao! Were you able to make it work in android as well? I'm getting requests from android if the app is in background but not when its in foreground.

@ivankennethwang In my case, the code for Android notifications was already implemented, so I can't help you much with that. Check the README, once again, and be sure to setup your listeners on the root of your app, that should test wether the notification was received in foreground (notification.foreground) and, in that case, render some modal, for example, to announce that same notification

Was this page helpful?
0 / 5 - 0 ratings