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
});
}
});
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
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.