user3797599 user3797599 - 1 year ago 204
Objective-C Question

call of [[UIApplication sharedApplication] currentUserNotificationSettings].types returns always UIUserNotificationTypeNone

I need to check if user have enabled push notifications in Settings. For this I use this code:

if ([[UIApplication sharedApplication] isRegisteredForRemoteNotifications] == NO) {
// NO
if ([[UIApplication sharedApplication]respondsToSelector:@selector(currentUserNotificationSettings)]){
UIUserNotificationSettings *noticationSettings = [[UIApplication sharedApplication] currentUserNotificationSettings];
if (!noticationSettings || (noticationSettings.types == UIUserNotificationTypeNone)) {
// here it does not work, I enabled push notifications
// in settings and noticationSettings.types returns UIUserNotificationTypeNone
// NO
} else {
// YES

but problem is that noticationSettings.types returns alwyas UIUserNotificationTypeNone, regardless whether are push notifications enabled in Settings or not.

As you can see on the picture, I have enabled push notifications, but noticationSettings.types returns me UIUserNotificationTypeNone, can anybody tell me where could be the problem? Thanks

enter image description here


Your screenshot indicates that you did not call registerUserNotificationSettings with UIUserNotificationTypeBadge or UIUserNotificationTypeSound or UIUserNotificationTypeAlert.

Try the following:

UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge
                                                                                     |UIUserNotificationTypeAlert) categories:nil];

UIApplication *application = [UIApplication sharedApplication];
[application registerUserNotificationSettings:settings];