具有推播通知功能的React Native应用程序在启动时崩溃

时间:2018-07-26 09:33:37

标签: react-native push-notification firebase-cloud-messaging react-native-fcm

我正在尝试通过react-native-fcm接收推送通知。正如文档所述,我将在下面安装并实施所有步骤

a)安装react-native-fcm npm install react-native-fcm --save

b)用react-native link react-native-fcm

链接库

c)从firebase控制台下载GoogleService-Info.plist文件并将其放在/ ios / my-project目录

d)使用Cocoapods安装Firebase消息传递  1. cd ios && pod初始化  2.将pod 'Firebase/Messaging'添加到Podfile中  3. pod install

e)编辑AppDelegate.h

@import UserNotifications;
@interface AppDelegate : UIResponder <UIApplicationDelegate,UNUserNotificationCenterDelegate>
/*@interface AppDelegate : UIResponder <UIApplicationDelegate>*/

f)修改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

-(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];
}

g)启用功能

  1. 推送通知
  2. 背景模式>远程通知

然后,我将应用程序存档在ipa中,并尝试在设备上启动它。出现加载屏幕后,应用程序崩溃。拜托,向我解释,我的错误在哪里?

PS。没有一个.js文件没有通过create-react-native-app命令更改。

1 个答案:

答案 0 :(得分:1)

请仔细阅读注释,他已经解释了为什么您应该切换到react-native-firebase

NOTES of react native fcm