4

react-native firebase request permissions always result in an exception.

I am trying to give the user the option to allow notifications in my react-native app. So, when the user install my react-native app an alert will be shown and he can choose whether to allow notifications on the app or not. I am using react-native-firebase to handle this. however, the firebase "requestPermission" function always fails whatever I click "allow" or "Not Allow".

firebase.messaging().requestPermission()
      .then(() => {
        console.log('User Now Has Permission')
      })
    .catch((error) => {
      console.log('Error', error)
    })



  • Can you post the error that is logged when it fails? – nicholascm Jul 30 '19 at 13:53
  • thank you nicholascm, the error is: `Error: Failed to grant permission` at createErrorFromErrorData (NativeModules.js:155) at NativeModules.js:104 at MessageQueue.__invokeCallback (MessageQueue.js:414) at MessageQueue.js:127 at MessageQueue.__guard (MessageQueue.js:314) at MessageQueue.invokeCallbackAndReturnFlushedQueue (MessageQueue.js:126) at debuggerWorker.js:80 – Abdulmughni Hamzah Jul 31 '19 at 09:12

1 Answers1

0

thank you all, I resolved it via setting requestPermissions: false, in

configurePushNotification = (callBack) => {
    PushNotification.configure({
      // (required) Called when a remote or local notification is opened or received
      onNotification: callBack,

      // IOS ONLY (optional): default: all - Permissions to register.
      permissions: {
        alert: true,
        badge: true,
        sound: true,
      },

      // Should the initial notification be popped automatically
      // default: true
      popInitialNotification: true,

      /**
       * (optional) default: true
       * - Specified if permissions (ios) and token (android and ios) will requested or not,
       * - if not, you must call PushNotificationsHandler.requestPermissions() later
       */
      requestPermissions: false,
    })
  }