skip to Main Content

I have implemented push notification for android and it work 100% correctly but when I open the same app to test push notification for IOS it fails as it requires for a config file here is my config file code:

 import { firebase } from '@react-native-firebase/messaging';
 const reactNativeFirebaseConfig = {
 apiKey: "my apiKey",
 ...
 ...
 measurementId: "my measurementID XYZ"
};
firebase.initializeApp(reactNativeFirebaseConfig);

now the issue is even after adding this to my project gives an error: No Firebase App ‘[DEFAULT]’ has been created – call firebase.initializeApp()

Note: I am using ‘@react-native-firebase/app’; and ‘@react-native-firebase/messaging’ for push notification which is working for Android. anyone knows what is wrong on my code side or where should I use that config file as I saved this file as FirebaseConfig.js.

2

Answers


  1. To setup Firebase on iOS, you need to do a few extra steps.

    Open Firebase, and create a new iOS app.

    Fill in the bundle identifier and give it a nickname of your choice.

    Next download the google services file and open xCode.

    Drag the Google Services file into the file tree yourApp/yourApp, next to your AppDelegate.m file.

    Open AppDelegate.m and add

    #import <Firebase.h>
    

    to the top.

    Next, at around line 58 there should be a return YES.

    Add this above the return

    [FIRApp configure];
    

    Lastly, after the return and close bracket, add this code.

    - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
      [FIRMessaging messaging].APNSToken = deviceToken;
    }
    

    All together it should look similar to this.

      UIViewController *rootViewController = [UIViewController new];
      rootViewController.view = rootView;
      self.window.rootViewController = rootViewController;
      [self.window makeKeyAndVisible];
    
      [FIRApp configure];
    
      return YES;
    }
    
    - (void)application:(UIApplication *)application 
    didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
      [FIRMessaging messaging].APNSToken = deviceToken;
    }
    

    After you’ve done that, you should be all set to send your first message to your app.

    Bare in mind that Firebase isn’t very quick to send messages, it can take a few minutes to come through.

    Side-note you cant sent notifications to a iOS simulator, only a real device. You also need to add Notification permission to the app in your Apple developer account, and in xCode.

    If you need help setting this up, let me know and we can Skype.

    Login or Signup to reply.
  2. You need to add a check in the following file’s method didFinishLuanchWithOptions ios/{AppName}/AppDelegate.m

    if ([FIRApp defaultApp] == nil) {
     [FIRApp configure]; 
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search