首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在启动时用推送通知功能响应本机应用程序

在启动时用推送通知功能响应本机应用程序
EN

Stack Overflow用户
提问于 2018-07-26 09:33:36
回答 1查看 681关注 0票数 0

我正在尝试用react-native-fcm接收推送通知。如文档所述,请按以下方式安装和实现所有步骤

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

( b)将库与react-native link react-native-fcm连接

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

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

( e)编辑AppDelegate.h

代码语言:javascript
复制
@import UserNotifications;
@interface AppDelegate : UIResponder <UIApplicationDelegate,UNUserNotificationCenterDelegate>
/*@interface AppDelegate : UIResponder <UIApplicationDelegate>*/

( f)编辑AppDelegate.m

代码语言:javascript
复制
#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命令。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-07-26 09:42:26

请仔细看一看笔记,他已经解释了为什么你要切换到反应本土化的火力基地。

反应本机fcm注记

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51535594

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档