gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 13:58:01 24 4
gpt4 key购买 nike

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com