Mic*_*nko 3 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');
}
Run Code Online (Sandbox Code Playgroud)
我的问题出FirebaseAppDelegateProxyEnabled在info.plist. 设置NO此标志允许从 APN 向 FCM 发送消息。这就是为什么我能够通过 APNs 令牌但不能通过 FCM 令牌发送接收推送通知。设置此标志来YES解决我的问题。
| 归档时间: |
|
| 查看次数: |
6862 次 |
| 最近记录: |