我正在测试反应原生的PushNotification IOS. http://facebook.github.io/react-native/docs/pushnotificationios.html#content 我在componentWillMount函数中绑定如下所示的事件 PushNotificationIOS.addEventListener('notification
http://facebook.github.io/react-native/docs/pushnotificationios.html#content
我在componentWillMount函数中绑定如下所示的事件
PushNotificationIOS.addEventListener('notification', this._onNotification);
我从服务器向设备发送推送通知.
它没有捕获推送通知.
我只能在对象c代码下面收到推送通知
(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { }
PushNotificationIOS可以监听RCTDeviceEventEmitter调用.
但是来自服务器的通知无法收听.
有谁知道这个问题?
推送通知不是开箱即用的,React Native文档中没有记录这一点.您需要首先向项目添加一些内容才能连接通知.我在github https://github.com/facebook/react-native/pull/1979#issue-94795697上的一个公开问题中找到了这些信息.您基本上需要在AppDelegate.m中手动连接通知并从RCTPushNotificationManager调用相应的方法,以便PushNotificationsIOS类可以从您的javascript代码处理它们.
>将RCTPushNotification添加到项目中(还可以在构建设置中链接二进制文件).
>将此标题添加到标题搜索路径:$(SRCROOT)/ node_modules / react-native / Libraries / **
>将此代码添加到AppDelegate.m:
#import "RCTPushNotificationManager.h" - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { [RCTPushNotificationManager application:application didFailToRegisterForRemoteNotificationsWithError:error]; } - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { [RCTPushNotificationManager application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; } - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)notification { [RCTPushNotificationManager application:application didReceiveRemoteNotification:notification]; }