3

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.

mayank goyal
  • 41
  • 1
  • 1
  • 6

4 Answers4

5

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.

rptwsthi
  • 10,094
  • 10
  • 68
  • 109
  • 1
    but 'notification' permission using react-native-permission only works with ios and not with android. – mayank goyal Nov 19 '18 at 09:49
  • That is why added "another library". – rptwsthi Nov 19 '18 at 09:50
  • As of today, the "react-native-permissions" describes itself as "A unified permissions API for React Native on iOS, Android and Windows.", so maybe they updated it =) – Ted Jan 18 '23 at 11:52
4

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

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

requestNotifications(['alert', 'sound']).then(({status, settings}) => {
  // …
});
FDisk
  • 8,493
  • 2
  • 47
  • 52
0

Android:

Actually the Push Notification permission lie in Normal Category Permission like INTERNET permission not in Dangerous Category Permission.

You don't have to ask for Push Notification permissions.

More details is here, https://stackoverflow.com/a/37294287/7188778

Andrii Sikora
  • 31
  • 1
  • 5
0

You can use Notifee Library package to request for notification permission for both (ios and android) and also you can check the permission status but i don't think there is a package which states whether permission is switched off by user.

kousic
  • 31
  • 2