You are not receiving notification probably because firebase is not integrated properly in your application. The steps to integrate properly are given below:
react-native-firebase library did not work for me .Integrating firebase to react native application using react-native-fcm succeded in receiving push notifications.
1.Install react-native-fcm:
npm install react-native-fcm --save
- From firebase console,
for Android: download google-services.json file and place it in android/app directory.
for iOS: download GoogleService-Info.plist file and place it in /ios/your-project-name directory (next to your Info.plist)
3.Configure the project using :
cd ios && pod init
4.Edit the newly created Podfile:
pod install
5.Edit AppDelegate.h:
@import UserNotifications;
@interface AppDelegate:UIResponder<UIApplicationDelegate,UNUserNotificationCenterDelegate>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
6.Edit AppDelegate.m:
#import "RNFIRMessaging.h"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[FIRApp configure];
[[UNUserNotificationCenter currentNotificationCenter] setDelegate:self];
return YES;
}
-(void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^) .
(UNNotificationPresentationOptions))completionHandler
{
[RNFIRMessaging willPresentNotification:notification
withCompletionHandler:completionHandler];
}
#if defined(__IPHONE_11_0)
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void (^)(void))completionHandler
{
[RNFIRMessaging didReceiveNotificationResponse:response
withCompletionHandler:completionHandler];
}
#else
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void(^)())completionHandler
{
[RNFIRMessaging didReceiveNotificationResponse:response
withCompletionHandler:completionHandler];
}
#endif
//You can skip this method if you don't want to use local notification
-(void)application:(UIApplication *)application
didReceiveLocalNotification:(UILocalNotification *)notification {
[RNFIRMessaging didReceiveLocalNotification:notification];
}
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo
fetchCompletionHandler:(nonnull void (^) .
(UIBackgroundFetchResult))completionHandler{
[RNFIRMessaging didReceiveRemoteNotification:userInfo
fetchCompletionHandler:completionHandler];
}
7.Add the path of header files into XCode:
Open XCode.
Press CMD+1 or click the XCode project.
Go to Build Settings, selecting All and Combined.
Search Header Search Path in the searchg tab.
Make sure there is a line of $(SRCROOT)/../node_modules/react-native-fcm/ios. If no, just add it.
8.Add GoogleService-Info.plist:
Make sure the file is not just moved into the folder. You need to Right Click the project folder in XCode and Add File to . Select Copy if needed in the Options page while selecting the file.
9.Shared Library Settings:
Make sure you see Pods.xcodeproj under Library folder if you are using Pod install method.
Make sure you see RNFIRMessaging.xcodeproj under Library folder.
If you don't see any of these files, please add them by Right Click the Library folder and Add File to to add them back. Pods.xcodeproj should be under ios/Pods/, and RNFIRMessaging.xcodeproj should be under node_modules/react-native-fcm/ios.
Make sure you see libRNFIRMessaging.a under Link Binary With Libraries under Build Phases tab. If no, drag the file under RNFIRMessaging.xcodeproj under Library folder into there.
10.Add Capabilities
Select your project Capabilities and enable:
Push Notifications
Background Modes > Remote notifications.
FirebaseAppDelegateProxyEnabled
This instruction assumes that you have FirebaseAppDelegateProxyEnabled=YES (default) so that Firebase will hook on push notification registration events. If you turn this flag off, you will be on your own to manage APNS tokens and link with Firebase token.