skip to Main Content

I am using expo push-notification library to generate device push token and using it to send the notifications to the devices. It is working fine in expo managed workflow but when i am using the function

token = await Notifications.getExpoPushTokenAsync({});

i am getting an error which says :-
[Error: Call to function ‘ExpoPushTokenManager.getDevicePushTokenAsync’ has been rejected.
→ Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.notifications. Make sure to call FirebaseApp.initializeApp(Context) first.]

Can anyone please tell how to solve this error? I have tried everything but nothing seems to work.

I have tried to initialize the firebase app using the docs but it did not work as expected and it was giving the same error.

2

Answers


  1. You need to pass the projectId in the object. You can find your projectId in app.json.

    docs: https://docs.expo.dev/push-notifications/push-notifications-setup/

      await getExpoPushTokenAsync({
        projectId: "your-project-id"
      })
    
    Login or Signup to reply.
  2. The error says it all, you missing firebase app initialization :
    in the root of your app:

    import { initializeApp } from "firebase/app";
    
    // Initialize Firebase
    export const app = initializeApp({ pass your firebase config });
    

    also make sure to correctly get your token:

    const {data: token} = await Notifications.getExpoPushTokenAsync({
      projectId : // your projectId
    })
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search