I am trying to detect the Local notification settings for the App in iOS 8
for UIUserNotificationSettings
, it returns me 7 as I have turned on all Badge
check this out. code is tried and tested.
- (BOOL)isUserNotificationAllowed {
UIUserNotificationType types = [[UIApplication sharedApplication] currentUserNotificationSettings].types;
if(types & UIUserNotificationTypeBadge || types & UIUserNotificationTypeSound || types & UIUserNotificationTypeAlert){
return YES;
}
else {
return NO;
}
}
You can control the hash value of UIApplication.sharedApplication().currentUserNotificationSettings()
.
if(UIApplication.instancesRespondToSelector(Selector("registerUserNotificationSettings:"))){
if(UIApplication.sharedApplication().currentUserNotificationSettings().hashValue == 0){
pushNotificationStatus = "false"
} else {
pushNotificationStatus = "true"
}
}
Swift 3+
let isRegisteredForLocalNotifications = UIApplication.shared.currentUserNotificationSettings?.types.contains(UIUserNotificationType.alert) ?? false
Swift 2.3
let isRegisteredForLocalNotifications = UIApplication.sharedApplication().currentUserNotificationSettings()?.types.contains(UIUserNotificationType.Alert) ?? false
UIUserNotificationType notificationType = [[[UIApplication sharedApplication] currentUserNotificationSettings] types];
if(notificationType == UIRemoteNotificationTypeNone)
{
NSLog(@"OFF");
}
else{
NSLog(@"ON");
}
works for me
Method enabledRemoteNotificationTypes
is deprecated since iOS8.
To check remote notifications status in iOS8 you can call
[[UIApplication sharedApplication] isRegisteredForRemoteNotifications];
it will return NO if user disable notifications in Settings. Documentation on isRegisteredForRemoteNotifications
Or you can retrieve all current notification settings:
[[UIApplication sharedApplication] currentUserNotificationSettings];
Documentation on currentUserNotificationSettings