react-nativefirebase-cloud-messagingapple-push-notificationsdevicetoken

Trying to get iOS device token by using firebase message in React Native


Below is the steps implemented in React Native code - Do i have to add any steps or methods in iOS side? Certificate is APNS enable.

Step 1:

# Install & setup the app module
yarn add @react-native-firebase/app

# Install the messaging module
yarn add @react-native-firebase/messaging

# If you're developing your app using iOS, run this command
cd ios/ && pod install


const getDeviceToken = firebase.messaging().getAPNSToken();
  if (getDeviceToken) {
    console.log('getDeviceToken:', getDeviceToken);
  }

But the result i am getting in console is : { _U: 0, _V: 0, _W: null, _X: null } Note: I am running the project in Actual iOS device. Notification permission is already granted.


Solution

  • firebase.messaging().getAPNSToken() returns a promise. You can get your token when the promise is reloved like this:

    getDeviceToken.then( async (token) => {
      console.log('promise token: ', token);
    })