firebasereact-nativepush-notificationfirebase-cloud-messagingreact-native-fcm

React-native with Firebase FCM not working


I have done the following changes:

How is send notifications, using firebase-admin and getting successful result:

admin.messaging().sendToDevice(
        "token as string",
        {
        notification: {
            title: 'title here',
            body: 'body here'
            }
        },
        {
            priority: "high",
            contentAvailable: true,
            timeToLive: 2419200
        });

React-native code, this is when the application is in the foreground:

useEffect(() => {
    checkToken().then((token) => {
      console.log(token);
      // write to db
    });
    const unsubscribe = messaging().onMessage(async (remoteMessage) => {
      console.log(remoteMessage);
    });
    return unsubscribe;
  }, []);

I have the GoogleService-Info.plist file in the ios folder, I have uploaded the APNs in the firebase console + teamid + appid.

Following changes in AppDelegate.m:

#import <Firebase.h>
....
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

[FIRApp configure];

I am not receiving any notification while the app runs in the foreground, there must be something wrong with the way I am sending (probably I have the wrong options) or, what I have in react-native is wrongly configured, not sure. I am trying to do it only for IOS for now.

Any info or solution would be helpful.


Solution

  • I eventually fixed it by running a clean run on an actual device.