首页 > 解决方案 > 使用 RNFirebase 从 iOS 通知中心获取所有通知

问题描述

我正在使用 RNFirebase 5.20.1 构建一个 React Native 应用程序,并寻找一种在通知中心(适用于 iOS)中获取所有通知的方法,类似于getDeliveredNotificationshttps://facebook.github.io/react-native/docs/ 0.55/pushnotificationios#getdeliverednotifications)。

我在 RNFirebase 的源代码或文档中没有找到类似这种方法的东西(https://github.com/invertase/react-native-firebase/blob/v5.xx/ios/RNFirebase/notifications/RNFirebaseNotifications.m)。

RNFirebase 确实提供了一种方法removeAllDeliveredNotifications来清除通知中心的所有通知,但返回一个包含 void 的承诺,所以我也无法从中获取任何数据。

我也考虑过实现 RN PushNotificationIOS 库,但有点担心它会与 RNFirebase 冲突(与 RNFirebase 集成方法有重叠,而且我对本机代码的理解非常初级)。

有任何想法吗?也许我根本没有看到 RNFirebase 方法来做到这一点......

更新

所以我已经集成了 PushNotificationIOS 库,只是在 AppDelegate.m 文件中更改了一件事,它似乎已经奏效了——我能够从通知中心访问通知。

- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings { [[RNFirebaseMessaging instance] didRegisterUserNotificationSettings:notificationSettings]; [RCTPushNotificationManager didRegisterUserNotificationSettings:notificationSettings]; }

标签: iosreact-nativepush-notificationreact-native-firebase

解决方案


推荐阅读