我正在尝试通过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)启用功能
然后,我将应用程序存档在ipa
中,并尝试在设备上启动它。出现加载屏幕后,应用程序崩溃。拜托,向我解释,我的错误在哪里?
PS。没有一个.js
文件没有通过create-react-native-app
命令更改。