Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update code using enabledRemoteNotificationTypes because it is "not supported in iOS 8"?

this is the code i used for the RemoteNotificationType:

NSUInteger rntypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];

The error i got was this:

2014-09-29 15:46:47.416 Dummy[258:21766] enabledRemoteNotificationTypes is not supported in iOS 8.0 and later.

Would be a great help if someone could give me the solution.

like image 648
Christine Avatar asked Sep 29 '14 02:09

Christine


3 Answers

You can also use this code:

if ([[UIApplication sharedApplication] respondsToSelector:@selector(currentUserNotificationSettings)]) {

    UIUserNotificationType types = [[[UIApplication sharedApplication] currentUserNotificationSettings] types];

    if (types == UIUserNotificationTypeNone) {
        // Do something
    }

} else {

    UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];

    if (types == UIRemoteNotificationTypeNone) {
        // Do something
    }
}

Or this one if you only want to check the user is registered for remote notifications:

if ([[UIApplication sharedApplication] respondsToSelector:@selector(isRegisteredForRemoteNotifications)]) {

    BOOL isRegisteredForRemoteNotifications = [[UIApplication sharedApplication] isRegisteredForRemoteNotifications];

    if (isRegisteredForRemoteNotifications) { 
        // Do something
    }

} else {

    UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];

    if (types == UIRemoteNotificationTypeNone) {
        // Do something
    }
}
like image 77
dms90 Avatar answered Nov 18 '22 06:11

dms90


Use with this condition to give support in both iOS 7 and prior iOS 8

#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)

NSUInteger rntypes;
  if (!SYSTEM_VERSION_LESS_THAN(@"8.0")) {
   rntypes = [[[UIApplication sharedApplication] currentUserNotificationSettings] types];
}else{
   rntypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
}
like image 16
hardikdevios Avatar answered Nov 18 '22 08:11

hardikdevios


Please use following methods -

[[UIApplication sharedApplication] isRegisteredForRemoteNotifications]

or

[[UIApplication sharedApplication] currentUserNotificationSettings]

to retrieve user-enabled remote notification and user notification settings in iOS 8.

like image 2
Urmi Avatar answered Nov 18 '22 07:11

Urmi