iosios8apple-push-notifications

Strange behavior of registerUserNotificationSettings in iOS8


I try to register only alert type notification at application start in

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

by calling

UIUserNotificationType types = UIUserNotificationTypeAlert;

UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types categories:nil];

[[UIApplication sharedApplication] registerUserNotificationSettings:settings];

In

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

I permanently get all types in notificationSettings

<UIUserNotificationSettings: 0x16dd6160; types: (UIUserNotificationTypeAlert UIUserNotificationTypeBadge UIUserNotificationTypeSound);>

And

UIUserNotificationSettings *settings = [[UIApplication sharedApplication] currentUserNotificationSettings]

gives me the same all types despite my initial choice of the only alert type.

So I can't setup restricted dynamical permissions on start.

There is no any information about similar problems in the internet.


Solution

  • It seems that it is impossible to setup UserNotificationType from application in iOS8 (at least). One needs to use general Notification Center to set any combination of sound, badge and alert. Only the first attempt to register which occurs with Push notification permissions alert sets UserNotificationType needed.

    Another way is to send UserNotificationType on subscription to your push server which should make payload depending of this type.