Registering for local notification returns UIUserNotificationTypeNone after user chooses "Allow" on iOS9

1.4k views Asked by At

This has worked in iOS 8 and prior, so it may be a bug in iOS 9 beta - or it's a changed behaviour.

After asking the user for permission to send local notifications -

        NSSet *categories = ...;
        UIUserNotificationType notificationTypes = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
        UIUserNotificationSettings *notificationSettings = [UIUserNotificationSettings settingsForTypes:notificationTypes categories:categories];

        [[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];

and user chooses "Allow", application:didRegisterUserNotificationSettings: is called with [notificationSettings types] == UIUserNotificationTypeNone.

However, the next time I run registerUserNotificationSettings it will be called with the correct permission types.

Apple's reference doesn't say anything that may indicate this is intended, so it may be a bug.

Anyone knows what's the problem or how to work around it?

2

There are 2 answers

1
Nilesh Patel On

Just found that Apple have modified their didRegisterUserNotificationSettings method

From

 - (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings

To

- (void)application:(UIApplication * nonnull)application didRegisterUserNotificationSettings:(UIUserNotificationSettings * nonnull)notificationSettings

Don't know wether this will resolve issue but you can try.

0
Tomas Camin On

You can workaround this behaviour (which kinda looks like a bug) by checking [application currentUserNotificationSettings] in application:didRegisterUserNotificationSettings: instead