Default FirebaseApp is not initialized in this process - React Native - Local Notification

5.4k Views Asked by At

(Before you mark this question as duplicate, please read the whole question)

I am using react-native-push-notification library in my React-Native Application.

In my app I have not initialized Firebase because I do not need any remote notifications as of now. Currently I am scheduling a local notification and when the notification comes I am expecting user actions from it. Based on the button pressed I want to make appropriate API calls.

So to achieve this I used PushNotification.configure method, but it is throwing me "Default FirebaseApp is not initialized in this process. Make sure Firebase is initialised" error.

I am being forced to use Firebase, when I have absolutely no need of it.

Could someone please help me out here, I have been searching for answer from past 2 days. I am quite new to React Native and I am still learning it. Any help is appreciated.

Thanks

2

There are 2 best solutions below

4
On

Finally I found the solution, it was actually in the documentation itself but I somehow over looked. I will post it here because I am sure there's someone like me out there.

We are supposed to add requestPermissions: Platform.OS === 'ios', in PushNotification.configure like this:

PushNotification.configure({
    onNotification: function (notification) {
      console.log('LOCAL NOTIFICATION ==>', notification);
    },

    // This line solves the problem that I was facing.
    requestPermissions: Platform.OS === 'ios',
  });
0
On

The accepted answer no longer works when using Android API version ≥ 33.


Problem

The problem is that by setting

requestPermissions: Platform.OS === 'ios'

permissions will never be requested, and changing it to true or running PushNotification.requestPermissions() manually will always throw the "Default FirebaseApp is not initialized in this process. Make sure Firebase is initialized." error.

The only workaround is to have users go into app settings and toggle the notification permission manually.

Unfortunately, as react-native-push-notification hasn't been updated since 2021 and appears abandoned, it can no longer be used for local notifications without Firebase support on latest Android versions.


Solution

Use @notifee/react-native