无论我选择“允许”还是“不允许”,我对 firebase.messaging.requestPermission() 总是会导致异常

问题描述 投票:0回答:1

react-native firebase 请求权限总是导致异常。

我正在尝试为用户提供允许在我的本机反应应用程序中进行通知的选项。因此,当用户安装我的 react-native 应用程序时,将显示一个警告,他可以选择是否允许在应用程序上发送通知。我正在使用 react-native-firebase 来处理这个问题。然而,无论我点击“允许”还是“不允许”,firebase 的“requestPermission”功能总是失败。

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



react-native react-native-firebase
1个回答
0
投票

谢谢大家,我通过设置 requestPermissions: false 解决了这个问题, 在

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,
    })
  }
© www.soinside.com 2019 - 2024. All rights reserved.