Sammio2 Sammio2 - 1 month ago 16
Objective-C Question

How to interrogate UIUserNotificationSettings types

I am trying to implement the

application:didRegisterUserNotificationSettings:
App Delegate method to try and identify if i am allowed to send local notifications to the user in iOS 8. The following is the kind of thing i'm trying to achieve, but this is obviously the incorrect way of going about it.

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

if (notificationSettings.types /*How do i check which types are contained */) {

NSLog(@"Allowed");

} else {

NSLog(@"Not Allowed");
}

}

Answer

Here you go

if (notificationSettings.types == UIUserNotificationTypeNone) {
      NSlog(@"Permission not Granted by user");
}
else{
      NSlog(@"Permission Granted");
}

To interrogate a specific setting:

BOOL allowsSound = (notifSettings.types & UIUserNotificationTypeSound) != 0;