无法接收FCM(推送通知iOS)

时间:2020-01-03 07:43:05

标签: ios firebase react-native

我通过原生制作应用。 几天前,我能够收到 FCM 。但是现在我不能。

客户端应用程序权限通知,我设置了Xcode(功能),firebase和Apple Developer(APNs设置)。

console.log告诉我成功。

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

这是Firebase中的错误吗?

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

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

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

========添加=======

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

APN仅在一天内有效?

1 个答案:

答案 0 :(得分:0)

很可能在您的Firebase控制台中,当前有资格参加此广告系列的潜在用户为0。

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

enter image description here

可能的解决方案:

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)检查证书是否已过期(不太可能),因为您提到它几天前仍在工作。