【问题标题】:React Native application with Push notification capability crashes on start具有推送通知功能的 React Native 应用程序在启动时崩溃
【发布时间】:2018-07-26 09:33:36
【问题描述】:

我正在尝试使用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 命令更改。

【问题讨论】:

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


    【解决方案1】:

    请仔细阅读笔记,他解释了为什么你应该切换到 react-native-firebase

    NOTES of react native fcm

    【讨论】:

    • 感谢您的回答,但当前的react-native-fcm 也应该可以使用
    • 我找到了为什么应用程序由于您的链接而崩溃。非常感谢,React-native-firebase 也很棒!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多