react-nativepush-notificationfirebase-cloud-messagingreact-native-fcm

React Native application with Push notification capability crashes on start


I'am trying to receive push notification with react-native-fcm. As documentation says I'am install and implement all steps as bellow

a) Install react-native-fcm npm install react-native-fcm --save

b) Link the library with react-native link react-native-fcm

c) Download GoogleService-Info.plist file from firebase console and place it in /ios/my-project directory

d) Install Firebase Messaging with Cocoapods 1. cd ios && pod init 2. add pod 'Firebase/Messaging' into Podfile 3. pod install

e) Edit AppDelegate.h

@import UserNotifications;
@interface AppDelegate : UIResponder <UIApplicationDelegate,UNUserNotificationCenterDelegate>
/*@interface AppDelegate : UIResponder <UIApplicationDelegate>*/

f) 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

-(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];
}

g) Enable capabilities

  1. Push Notifications
  2. Background Modes > Remote notifications

Then I archive my application in ipa and try to start it on device. Application crashes after loading screen appear. Please, explan to me, where is my mistake?

PS. No one .js file are not change from create-react-native-app command.


Solution

  • Please go through the notes , he has explain as why you should switch to react-native-firebase

    NOTES of react native fcm