Skip to content
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

PushNotificationIOS requestPermission promisified #7900

Closed
wants to merge 8 commits into from
Prev Previous commit
Next Next commit
short hand to create notification types
  • Loading branch information
JAStanton committed Jun 3, 2016
commit 636517562a54fd7570d03cba836397057a4fb3c1
21 changes: 9 additions & 12 deletions Libraries/PushNotificationIOS/RCTPushNotificationManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,16 @@ - (void)handleRemoteNotificationsRegistered:(NSNotification *)notification

- (void)handleRegisterUserNotificationSettings:(NSNotification *)notification
{
if (self.requestPermissionsResolveBlock == nil) return;

NSMutableDictionary* notificationTypes = [NSMutableDictionary dictionaryWithObjectsAndKeys:@NO, @"alert", @NO, @"badge", @NO, @"sound", nil];
UIUserNotificationSettings *notificationSettings = notification.userInfo;
if (notificationSettings.types & UIUserNotificationTypeAlert) {
notificationTypes[@"alert"] = @YES;
}
if (notificationSettings.types & UIUserNotificationTypeSound) {
notificationTypes[@"sound"] = @YES;
}
if (notificationSettings.types & UIUserNotificationTypeBadge) {
notificationTypes[@"badge"] = @YES;
if (self.requestPermissionsResolveBlock == nil) {
return;
}
UIUserNotificationSettings *notificationSettings = notification.userInfo;
Copy link
Contributor

@nicklockwood nicklockwood Jun 3, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JAStanton This failed to land due to a type error detected by our build system. You're assigning notification.userInfo (which is defined as being an NSDictionary) to a property of type UIUserNotificationSettings. I'm not sure why this worked for you locally, but it seems unlikely that it's correct.

Copy link
Contributor Author

@JAStanton JAStanton Jun 3, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh nice, so it works because I was passing in UIUserNotificationSettings to the userInfo parameter of my NSNotification message instead of setting it a dictionary like how it's supposed to be used. Bummer. Updated, take a look! Thanks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JAStanton ah, I totally missed that. Should just be a simple case of wrapping notificationSettings in a dictionary and then unwrapping it then:

@{ @"settings": notificationSettings }

NSDictionary *notificationTypes = @{
@"alert": [NSNumber numberWithBool:notificationSettings.types & UIUserNotificationTypeAlert],
@"sound": [NSNumber numberWithBool:notificationSettings.types & UIUserNotificationTypeSound],
@"badge": [NSNumber numberWithBool:notificationSettings.types & UIUserNotificationTypeBadge],
};

self.requestPermissionsResolveBlock(notificationTypes);
self.requestPermissionsResolveBlock = nil;
}
Expand Down