【问题标题】:react native ios objective c, can't receive push notifications in foreground反应本机ios目标c,无法在前台接收推送通知
【发布时间】:2024-05-02 17:55:02
【问题描述】:

我使用带有 Firebase 云消息传递的原生推送通知来处理接收推送。 我的问题是我无法在前台收到推送。

我的代码是:

 // Receive displayed notifications for iOS 10 devices.
// Handle incoming notification messages while app is in the foreground.
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
       willPresentNotification:(UNNotification *)notification
         withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
  NSDictionary *userInfo = notification.request.content.userInfo;

  // With swizzling disabled you must let Messaging know about the message, for Analytics
  [[FIRMessaging messaging] appDidReceiveMessage:userInfo];

  // Print message ID.
  if (userInfo[kGCMMessageIDKey]) {
    NSLog(@"Message ID: %@", userInfo[kGCMMessageIDKey]);
  }

  // Print full message.
  NSLog(@"%@", userInfo);

  // Change this to your preferred presentation option
  completionHandler(UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionAlert);
}

【问题讨论】:

    标签: ios objective-c firebase react-native push-notification


    【解决方案1】:

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

    此链接将对您有所帮助,先生。

    你好,本教程适用于这个问题,尤其是在

    import io.invertase.firebase.notifications.RNFirebaseNotificationsPackage;
    

    RNFirebaseNotificationsPackage,我们遇到了同样的问题,并通过添加包修复了它:)

    【讨论】:

    • 我的问题是 ios 而不是 android
    • 先生,请查看包含 IOS 解决方案的文章。
    • 我看到这篇文章是FCM的旧版本,我用的是最新版本
    【解决方案2】:

    在 FCM 中,如果您已经在前台,则不会显示通知。

    您可以处理 3 种不同的推送通知情况。

    1. 前景
    2. 背景
    3. 退出(应用未运行)

    在情况 2、3 中,您似乎处理正确。 在情况 1 中,您必须在本地手动显示您的推送通知。

    【讨论】:

    • 我该怎么做?
    • 你有答案吗?