React-native-firebase: Request Permission

Created on 25 Apr 2018  路  4Comments  路  Source: invertase/react-native-firebase

How can request permission again next time, when user reject the permission.

firebase.messaging().hasPermission()
.then(enabled => {
  if (enabled) {
    // user has permissions
    console.log("have");
  } else {
    // user doesn't have permission
    console.log("no have");
    firebase.messaging().requestPermission()
    .then(() => {
      // User has authorised  
    })
    .catch(error => {
      // User has rejected permissions  
    });
  } 
});

Most helpful comment

Thanks @judemanutd

It's also worth noting that on iOS, if the user rejects permissions, you will have to direct them to the notification settings page in the OS to add the permissions. Prompting them for permissions again will not work as it's blocked by the OS.

You'll have to do this within your app, as it's not part of the library.

All 4 comments

This should work.

export default class fcmHandler extends React.PureComponent {

componentDidMount() {

firebase.messaging()
    .hasPermission()
    .then(enabled => {
        if (!enabled) {
            this._getPermission();
        }
    });
}

 _getPermission = () => {
    firebase.messaging()
        .requestPermission()
        .catch(error => {
            // User has rejected permissions
            this._getPermission();
        });
};

}

Thanks @judemanutd

It's also worth noting that on iOS, if the user rejects permissions, you will have to direct them to the notification settings page in the OS to add the permissions. Prompting them for permissions again will not work as it's blocked by the OS.

You'll have to do this within your app, as it's not part of the library.

@chrisbianca

you will have to direct them to the notification settings page in the OS to add the permissions.
Please help, how can I do this?

@chrisbianca

you will have to direct them to the notification settings page in the OS to add the permissions.
Please help, how can I do this?

Use Linking:
Linking.openURL(app-settings://notification/${yourBundleIdentifierHere});
More info here: https://forums.expo.io/t/api-to-open-app-settings/5290/3

Was this page helpful?
0 / 5 - 0 ratings

Related issues

matthieunelmes picture matthieunelmes  路  66Comments

AdamGold picture AdamGold  路  194Comments

jasan-s picture jasan-s  路  137Comments

umang-simform picture umang-simform  路  77Comments

gilbert picture gilbert  路  65Comments