react-native-fcm: Failed to grant permission ios 10.3.1

i am trying to use this code in iOS 10.3.1 but gettint error of failed to grant permissions:

componentDidMount(){
 if(Platform.OS === 'ios'){
   FCM.requestPermissions({badge: false, sound: true, alert: true});
      try {
        console.log("[Push] requestPermissions");
        const values = await FCM.requestPermissions({badge: false, sound: true, alert: true});
        console.log(values);
      } catch(err){
        console.log("[Push] requestPermissions error: " + err);
        return;
      }
 }
}

simulator screen shot 04-sep-2017 12 52 01 pm

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 28 (12 by maintainers)

Most upvoted comments

@natashache like @evollu says, the actual OS (on iOS) modal is only shown once, after that it returns the choice the user made; being acknowledged or rejected the notifications. In the code, you can dispatch the requestPermissions Promise. It will only resolve when the user accepted the permissions, it will reject if the user denied.

In our code, we handle it this way:

// on a specific 'why notifications' screen
FCM.requestPermissions()
      .then(e => dispatch(turnOnPushNotifications()))
      .catch(() => dispatch(turnOffPushNotifications()))
 
// in a 'notification controller' which listens to AppState changes and on ComponentDidMount
PushNotificationIOS.checkPermissions(
    (permissions: IOsPermissionState) => {
      if (permissions.alert === 1 || permissions.badge === 1 || permissions.sound === 1) {
        dispatch(turnOnPushNotifications())
      } else {
        dispatch(turnOffPushNotifications())
      }
    })

For now we only handle the iOS part since our Android app is not targeted for runtime notifications. This might change soon though… I hope this helps!