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

时间:2019-03-25 09:03:37

标签: 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');
    }

2 个答案:

答案 0 :(得分:0)

我认为您可能缺少配置IOS推送通知的详细信息步骤,您可以查看此博客,该博客已说明我们如何在IOS和android中同时配置FCM

https://medium.com/@anum.amin/react-native-integrating-push-notifications-using-fcm-349fff071591

答案 1 :(得分:0)

我的问题是在FirebaseAppDelegateProxyEnabled中的info.plist标志中。设置为NO,此标志允许从APN向FCM发送消息。这就是为什么我能够通过APNs令牌而非FCM令牌发送接收推送通知的原因。将此标志设置为YES可以解决我的问题。