首页 > 解决方案 > 无法接收 FCM(推送通知 iOS)

问题描述

我通过React Native制作应用程序。几天前,我收到了FCM。但现在我不能。

客户端应用权限通知,我设置了 Xcode(capability)、firebase 和 Apple Developer(APNs 设置)。

console.log 告诉我成功。

但我无法收到通知。虽然几天前我可以。

这是firebase中的错误吗?

我不知道原因,请帮助我m(_ _)m

=======环境==========

Xcode 11.3版 “react-native-firebase”:“ ^5.6.0 ”“react-native”:“ 0.61.5 ”“firebase-admin”:“ ^8.9.0

=======加法========

重新生成 APN 和设置,我可以收到通知。但是第二天,我无法收到通知。

APNs只有一天有效???

标签: iosfirebasereact-native

解决方案


最有可能的是,在您的 Firebase 控制台中,目前有资格参与此广告系列的潜在用户数量为 0。

“估计基于大约 0 个注册接收通知的用户。由于设备不活动,一些目标用户将看不到消息。对于重复活动,估计仅用于初始发送。”

在此处输入图像描述

可能的解决方案:

1)如果是这样(0个用户注册)

--> 检查是否收到了 fcmToken。

getFcmToken = async () => {
 const fcmToken = await firebase.messaging().getToken();
 if (fcmToken) {
  console.log(fcmToken);
  this.showAlert(‘Your Firebase Token is:’, fcmToken);
 } else {
  this.showAlert(‘Failed’, ‘No token received’);
 }
}

2)如果数字不为零

--> 很可能您的应用程序已在前台打开并且未显示通知。

--> 尝试锁定您的 iPhone 屏幕并显示通知,否则尝试处理应用程序在前台的通知

messageListener = async () => {
 this.notificationListener = firebase.notifications().onNotification((notification) => {
   const { title, body } = notification;
   this.showAlert(title, body);
 });

 this.notificationOpenedListener = firebase.notifications().onNotificationOpened((notificationOpen) => {
   const { title, body } = notificationOpen.notification;
   this.showAlert(title, body);
 });

 const notificationOpen = await firebase.notifications().getInitialNotification();
 if (notificationOpen) {
   const { title, body } = notificationOpen.notification;
   this.showAlert(title, body);
 }

 this.messageListener = firebase.messaging().onMessage((message) => {
  console.log(JSON.stringify(message));
 });
}

3)检查证书是否已过期(不太可能),因为您提到它几天前仍在工作。


推荐阅读