skip to Main Content

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.

2

Answers


  1. You need to make it async in order to wait for the token to be fetched from firebase

    use async await and it will work

    const getDeviceToken = await firebase.messaging().getAPNSToken();
      if (getDeviceToken) {
        console.log('getDeviceToken:', getDeviceToken);
      }
    
    Login or Signup to reply.
  2. 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);
    })
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search