ios - 无法从 ios 中的 react-native-firebase 接收通知消息

标签 ios react-native react-native-firebase

所以我在通知消息方面遇到了问题。我在 android 上成功连接了通知消息,并为 ios 提供了远程(仅数据)消息。但收不到通知或通知加数据信息。这是我捕获消息的代码:

const enabled = await firebase.messaging().hasPermission();
    if (enabled) {
        console.log('fcm enabled');

        const channel = new firebase.notifications.Android.Channel(
            'channelId',
            'Channel Name',
            firebase.notifications.Android.Importance.Max
        ).setDescription('A natural description of the channel');
        firebase.notifications().android.createChannel(channel);
        this.unsubscribeFromNotificationListener = firebase.notifications().onNotification((notification) => {
            console.log(notification);
            if (Platform.OS === 'android') {
                const localNotification = new firebase.notifications.Notification({
                    sound: 'default',
                    show_in_foreground: true,
                })
                    .setNotificationId(notification.notificationId)
                    .setTitle(notification.title)
                    .setSubtitle(notification.subtitle)
                    .setBody(notification.body)
                    .setData(notification.data)
                    .android.setChannelId('channelId')
                    .android.setColor('#000000')
                    .android.setSmallIcon(notification.android.smallIcon.icon)
                    .android.setPriority(firebase.notifications.Android.Priority.High);

                firebase.notifications()
                    .displayNotification(localNotification)
                    .catch(err => console.error(err));

            } else if (Platform.OS === 'ios') {
                console.log(notification);
                const localNotification = new firebase.notifications.Notification()
                    .setNotificationId(notification.notificationId)
                    .setTitle(notification.title)
                    .setSubtitle(notification.subtitle)
                    .setBody(notification.body)
                    .setData(notification.data)
                    .ios.setBadge(notification.ios.badge);

                firebase.notifications()
                    .displayNotification(localNotification)
                    .catch(err => console.error(err));

            }
        });
    } else {
        console.log('fcm not enabled');
    }

最佳答案

我的问题出在 info.plist 中的 FirebaseAppDelegateProxyEnabled 标志中。它被设置为 NO 此标志允许从 APNs 向 FCM 发送消息。这就是为什么我能够通过 APNs token 而不是通过 FCM token 发送接收推送通知。将此标志设置为 YES 解决了我的问题。

关于ios - 无法从 ios 中的 react-native-firebase 接收通知消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55334324/

相关文章:

ios - 仅在 ios 设备上 react native "No bundle URL present"

reactjs - 导航到另一个页面的后退按钮会导致底部选项卡消失并滑动到错误的方向

ios - React-native-firebase Bigimage 无法在 ios 中工作

iphone - IOS 是否有发送网页请求并在 iphone ios 上忘记它?

react-native - 在新项目中 react native 获取问题

ios - 使用 UIPrintPageRenderer 在打印的 pdf 中绘制水平线

android - 无法接收 firebase 云消息,react--native-firebase

firebase - 无法使用react-native-firebase创建Firebase动态链接 - React Native

iphone - 比较/设置字符串的最快方法

ios - Swift:检查存储在 NSMutableArray 值中的 JSON 值