Quantcast
Channel: Active questions tagged react-native+ios - Stack Overflow
Viewing all articles
Browse latest Browse all 16552

React Native handle IOS permissions for FCM messaging

$
0
0

I integrated FCM messaging to my React Native app.

In my App component i tried to grant permissions by asking the user if he accept to get notifications or not .

My question is, am i using to right way to grant permissions?

I use async componentDidMount to implement the function requestPermission :

import firebase from '@react-native-firebase/app'
import messaging from '@react-native-firebase/messaging'

async componentDidMount () {
 // ......
    const granted = messaging().requestPermission()
    if (granted) {
  console.log('User granted messaging permissions!')
  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
  firebase
    .messaging()
    .getToken()
    .then(fcmToken => {
      if (fcmToken) {
        // user has a device token
        console.log('fcm')
        console.log(fcmToken)
      } else {
        // user doesn't have a device token yet
        console.log('error')
      }
    })
  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
} else {
  console.log('User declined messaging permissions :(')
}
}

I get the FCM generated token, and i can send message using Postman to the device using this token. How can i be sure that the permissions are always granted and i can get the token from every device ? 

Viewing all articles
Browse latest Browse all 16552

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>