我正在ios React Native App中实现Firebase Push通知,
最初,我尝试使用无运气的react-native-firebase软件包,
然后我尝试使用react-native-fcm, 当我从Firebase控制台发送我的第一条消息时,按照react-native-fcm文档中的所有步骤进行操作后,我没有收到任何推送通知,但每次发送时“发送的FCMnotification收到但未注册任何侦听器” 消息如下img
我的安装过程如下
(1)创建firbase项目后,将googleservice-info.plist放置在项目文件夹中
(2)安装用于Firebase和Firebase /消息传递的容器
(3)npm install react-native-fcm --save
(4)react-native链接react-native-fcm
(5)在项目库中添加react-native-fcm .xcodeproj
(6)在构建阶段的“与库链接二进制文件”中添加libRNFIRmessaging.a
(7)在构建设置的标头搜索路径中添加$(SRCROOT)/../ node_modules / react-native-fcm / ios
(8)在appdelagate.h文件中添加以下代码
+ @import UserNotifications;
+
+ @interface AppDelegate : UIResponder <UIApplicationDelegate,UNUserNotificationCenterDelegate>
- @interface AppDelegate : UIResponder <UIApplicationDelegate>
(9)在Appdelegate.m文件中添加以下代码
+ #import "RNFIRMessaging.h"
//...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//...
+ [FIRApp configure];
+ [[UNUserNotificationCenter currentNotificationCenter] setDelegate:self];
return YES;
}
+
+ - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
+ {
+ [RNFIRMessaging willPresentNotification:notification withCompletionHandler:completionHandler];
+ }
+
+ #if defined(__IPHONE_11_0)
+ - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler
+ {
+ [RNFIRMessaging didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
+ }
+ #else
+ - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler
+ {
+ [RNFIRMessaging didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
+ }
+ #endif
+
+ //You can skip this method if you don't want to use local notification
+ -(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
+ [RNFIRMessaging didReceiveLocalNotification:notification];
+ }
+
+ - (void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler{
+ [RNFIRMessaging didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
+ }
(10)启用推送通知和远程通知功能
(11)步骤结束
我只想查看我的第一个推送通知
谢谢