Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i check push notification permission for both ios and android in react native?

I want to check push notification permission for both ios and android. I want to see if user has switched off the push notification permission from his device settings. Is there any plugin or any code i can take reference from if needed to be coded in native.

like image 519
mayank goyal Avatar asked Jan 28 '23 03:01

mayank goyal


2 Answers

You can check react-native-permissions npm. After integrating you can use it like:

componentDidMount() {
  Permissions.check('notification').then(response => {
    // Response is one of: 'authorized', 'denied', 'restricted', or 'undetermined'
    this.setState({ photoPermission: response })
  })
}

There is another library that can help (I have not used it).

There is also native implementation for as suggested here.

like image 111
rptwsthi Avatar answered Jan 29 '23 18:01

rptwsthi


Official way https://github.com/react-native-community/react-native-permissions#checknotifications

import {requestNotifications} from 'react-native-permissions';

requestNotifications(['alert', 'sound']).then(({status, settings}) => {
  // …
});
like image 31
FDisk Avatar answered Jan 29 '23 18:01

FDisk