Reputation: 75
I'm testing react-native PushNotificationIOS.
http://facebook.github.io/react-native/docs/pushnotificationios.html#content
I bind event like below in componentWillMount
function
PushNotificationIOS.addEventListener('notification', this._onNotification);
and I send push notification from server to device. It doesn't catch push notification.
I only can received push notification below object c code
(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
}
PushNotificationIOS
can listen with RCTDeviceEventEmitter
call.
but notification from server can't listen.
Does anyone know this problem?
Upvotes: 7
Views: 4953
Reputation: 888
Push notifications don't work out of the box and this is not documented on the React Native docs. There are a few things you need to add to your project first in order to wire up notifications. I found this information from an open issue on github https://github.com/facebook/react-native/pull/1979#issue-94795697.
You basically need to wire the notifications manually in AppDelegate.m and call the corresponding methods from the RCTPushNotificationManager so the PushNotificationsIOS class can handle them from your javascript code.
$(SRCROOT)/node_modules/react-native/Libraries/**
#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];
}
Upvotes: 7
Reputation: 11
I found this too so wrote a replacement module to handle receiving push notifications - https://github.com/darylrowland/react-native-remote-push
Upvotes: 1