1

I m working on push notification RN firebase, I have followed the rnfirebase documentation, I get the remote message in console.log but not displaying the notifcation on the xcode simulator.

Below are the relevant files screenshots and code

filename : notificationservices where i have added the respective react-native-firebase code snippets

import messaging from "@react-native-firebase/messaging";
import PushNotification from "react-native-push-notification";
import {PushNotificationIOS} from "@react-native-community/push-notification-ios";
import {Platform} from "react-native";

const getFcmToken = async () => {
    const fcmToken = await messaging()
        .registerDeviceForRemoteMessages()
        .then(() => messaging().getToken());
    console.log("fcmToken ==>", fcmToken);

    if (fcmToken) {
        console.log("Your Firebase Token is:", fcmToken);
    } else {
        console.log("Failed", "No token received");
    }
};

export const requestUserPermission = async () => {
    const authStatus = await messaging().requestPermission();
    const enabled =
        authStatus === messaging.AuthorizationStatus.AUTHORIZED ||
        authStatus === messaging.AuthorizationStatus.PROVISIONAL;

    if (enabled) {
        getFcmToken();
        console.log("Authorization status:", authStatus);
    }
};

export const notficationListener = async () => {
    messaging().onNotificationOpenedApp(remoteMessage => {
        console.log(
            "Notification caused app to open from background state:",
            remoteMessage.notification,
        );
    });
    messaging()
        .getInitialNotification()
        .then(remoteMessage => {
            if (remoteMessage) {
                console.log(
                    "Notification caused app to open from quit state:",
                    remoteMessage.notification,
                );
            }
        });
    messaging().onMessage(async remotemessage => {
        console.log("remote message11", JSON.stringify(remotemessage));
    });
    messaging().onNotificationOpenedApp(remotemessage => {
        console.log("remote message11", JSON.stringify(remotemessage));
        PushNotificationIOS.addNotificationRequest({
            id: remotemessage.messageId,
            title: remotemessage.notification.title,
            body: remotemessage.notification.body,
            sound: "default",
        });

        PushNotification.configure({
            onNotification: function (notification) {
                console.log("push notification");
                if (!notification.data) {
                    return;
                }
                notification.userInteraction = true;
                if (Platform.OS === "ios") {
                    notification.finish(PushNotificationIOS.FetchResult.NoData);
                }
            },
            senderId: "1054317504462",
            permissions: {
                alert: true,
                badge: true,
                sound: true,
            },
            popInitialNotification: true,
            requestPermissions: true,
        });
    });
};

export const remoteMessage = () => {
    const unsubscribe = messaging().onMessage(async remoteMessage1 => {
        console.log("A new FCM message arrived!", JSON.stringify(remoteMessage1));
    });
    return unsubscribe;
};

screenshot of Signing and Certificates in XCODE enter image description here

AppDelegate code

#import "AppDelegate.h"

#import <Firebase.h>
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import "RNNotifications.h"

#ifdef FB_SONARKIT_ENABLED
#import <FlipperKit/FlipperClient.h>
#import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h>
#import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h>
#import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h>
#import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h>
#import <FlipperKitReactPlugin/FlipperKitReactPlugin.h>

static void InitializeFlipper(UIApplication *application) {
  FlipperClient *client = [FlipperClient sharedClient];
  SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults];
  [client addPlugin:[[FlipperKitLayoutPlugin alloc] initWithRootNode:application withDescriptorMapper:layoutDescriptorMapper]];
  [client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]];
  [client addPlugin:[FlipperKitReactPlugin new]];
  [client addPlugin:[[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]];
  [client start];
}
#endif

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
 [FIRApp configure];
#ifdef FB_SONARKIT_ENABLED
  InitializeFlipper(application);
#endif

  RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
  RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
                                                   moduleName:@"AirU_App"
                                            initialProperties:nil];

  if (@available(iOS 13.0, *)) {
      rootView.backgroundColor = [UIColor systemBackgroundColor];
  } else {
      rootView.backgroundColor = [UIColor whiteColor];
  }

  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  UIViewController *rootViewController = [UIViewController new];
  rootViewController.view = rootView;
  self.window.rootViewController = rootViewController;
  [self.window makeKeyAndVisible];
  return YES;
}

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.