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 ?