-
Notifications
You must be signed in to change notification settings - Fork 24.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PushNotifications] Add an event for remote notification registration, and improve permissions request #1304
Conversation
@facebook-github-bot import |
Thanks for importing. If you are an FB employee go to https://our.intern.facebook.com/intern/opensource/github/pull_request/1067134919980570/int_phab to review. |
…missions to be requested
Squashed and rebased |
Just tried to run this on the iPhone 6 simulator and it couldn't build. Looks like your enum is not compatible with iOS8 |
I think if this is merged, then #1176 is closable. I'm looking forward to this being merged 👍 |
@@ -52,6 +57,21 @@ + (void)application:(UIApplication *)application didRegisterUserNotificationSett | |||
} | |||
} | |||
|
|||
+ (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I trying to use this fork, this line seems to be never called. Did I miss anything?
I'm not sure if I miss anything, but it seems to me the - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
NSMutableString *hexString = [NSMutableString string];
const unsigned char *bytes = [deviceToken bytes];
for (int i = 0; i < [deviceToken length]; i++) {
[hexString appendFormat:@"%02x", bytes[i]];
}
NSDictionary *userInfo = @{
@"deviceToken" : [hexString copy]
};
[[NSNotificationCenter defaultCenter] postNotificationName:@"RemoteNotificationsRegistered"
object:self
userInfo:userInfo];
} |
ping @ericvicenti , how is it going? |
@ericvicenti I'm assuming your comment was a typo, since I was having no trouble running on iOS 8 in the simulator or on device, but there were linker & enum errors with iOS 7.1. I made some adjustments to get the linker to cooperate again, things are working now on 7 and 8. @lazywei you're right, you need to call the public
You'll need to do the same thing if you want to respond to |
@andrewimm Great, thanks! I think this should be remarked on the doc, right? By the way, when doing this (I mean, calling |
@lazywei Being a total Objectiv-C n00b I struggled with the headers. To get it to work one needs to |
ping @ericvicenti how is this going? |
Sorry for all the delay on this! I'm not very familiar with iOS notifs and I had to fix an issue with iOS7/8 notif registration types. Good news is it has landed internally and will be synced to GH tomorrow morning! Thanks for all your patience on this |
@ericvicenti |
Can we please update the docs at https://facebook.github.io/react-native/docs/pushnotificationios.html to show users how to get a token that's already been registered? |
Figured it out - we should add a line:
|
I'm on 0.14.0-rc and the event doesnt seem to ever get triggered in my index.ios.js
|
Hi @Kevtastic. Did you add the listener functions to your AppDelegate.m? |
i did yeah, my appdelegate looks like this right now
then my js bundling stuff |
I think you also need to call PushNotificationIOS.requestPermissions() at least once. |
I'm calling requestPermissions inside of render right now, though I've tried to do it in componentWillMount and in componentDidMount. I've tried listening for the event before and after I request permissions but in both cases im not getting anything |
+1 same issue as @Kevtastic |
@ivanbrens As soon as I switched over to production certs and testflight it started working. I'm convinced development certificates have never worked for anyone ever. |
@Kevtastic development certs definitely worked when this code landed -- otherwise, I wouldn't have been able to test it. However, Apple has never supported notification registration in a Simulator, which is probably why things never worked until you moved to a physical device. It's unfortunate, but part of the iOS development experience. Thankfully, it's much easier to deploy to a physical device these days, now that app deploys can be tied to your iCloud account. |
In order to add Push support to the Parse JS SDK in React Native, we need a way to receive the APNS device token from the JS context. This adds another event to PushNotificationIOS, so that code can respond to a successful registration.
Additionally, I've updated the
requestPermissions
call to accept an optional map of parameters. This way, developers can request a subset of user notification types.