Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building for iOS if registerForRemoteNotificationTypes: is not supported in iOS 8.0 and later

If there are breaking changes with how devices register for notifications, and we cannot use registerForRemoteNotificationTypes: anymore, how can we build a new version of the app to support iOS 8 if we cannot use Xcode 6 beta? Will we have to build and submit the day the Xcode 6 GM version is released for our users to continue to get push notifications?

like image 576
Jason Hocker Avatar asked Aug 05 '14 20:08

Jason Hocker


3 Answers

iOS 8 has changed notification registration. So you need to check device version and then you need to register notification settings.(please check this link.) I try this code on Xcode 6 and its worked for me.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
        if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
        {
            [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
            [[UIApplication sharedApplication] registerForRemoteNotifications];
        }
        else
        {
            [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
             (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
        }

     return YES;
}
like image 71
Raşit ERASLAN Avatar answered Nov 06 '22 00:11

Raşit ERASLAN


You might want to consider using respondsToSelector rather than checking the system version:

if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]){
    [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
    [[UIApplication sharedApplication] registerForRemoteNotifications];
}
else{
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
     (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
}
like image 17
alex da franca Avatar answered Nov 05 '22 23:11

alex da franca


#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
    [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
    [[UIApplication sharedApplication] registerForRemoteNotifications];
#else
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
#endif
like image 11
Muhammad Adil Avatar answered Nov 05 '22 22:11

Muhammad Adil