react-native - 我有 firebase.messaging.requestPermission() 问题,无论我选择 'allow' 还是 'Not Allow',总是会导致异常

标签 react-native react-native-firebase

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

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

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



最佳答案

谢谢大家,我通过设置 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,
    })
  }

关于react-native - 我有 firebase.messaging.requestPermission() 问题,无论我选择 'allow' 还是 'Not Allow',总是会导致异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57271944/

相关文章:

javascript - 如何在 React Native 中截图测试?

react-native - 如何调用 Actions.pop() 并刷新之前的场景? React Native、Redux、React-Native-Router-Flux

react-native - 我可以在 React Native 中使用什么数据库

ios - React Native Firebase onAuthStateChanged 在注销后返回用户

android - Fresh Detached Expo + RNFirebase 未在 Android 上运行

ios - 无法编译 React Native iOS 应用程序以在物理设备上运行,React Native Firebase 出现问题

android - @react-native-firebase/admob 的基本用法给出 : "TypeError: (0, _admob.default) is not a function". 是否已弃用?或为什么不起作用?

javascript - 如何在 React Native 中将数据从一个屏幕发送到另一个屏幕?

react-native - 提供所需应用程序包的有效路径。打印 : Entry, ":CFBundleIdentifier",不存在

firebase - react native : managing notification on RNFirebase