How to use / maintain obsolete methods for older versions of iOS?

2

I'm developing an app for summers other than iOS, in this case for iOS 7 and iOS 8. I'm trying to create the Push Notification service, but the methods to register the app and others are "obsolete".

Below is the method I'm using:

[[UIApplication sharedApplication]

// obsoletos para o iOS 8
     registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];

    // Clear application badge when app launches

    application.applicationIconBadgeNumber = 0;
    
asked by anonymous 09.11.2014 / 22:42

2 answers

2

Check which version is running, and apply the code for each situation

    if ([[[UIDevice currentDevice] systemVersion] floatValue] < 8.0) {
     //Menor que iOS8
    }else{
    //Maior ou igual iOS8
    }
    
10.11.2014 / 00:14
2

Just check which method you can use in application:didFinishLaunchingWithOptions: .

// Verifica qual método utilizar com base no isRegisteredForRemoteNotifications (iOS 8)
if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)])
{
    // Registrar para notificações iOS 8
    [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
    [application registerForRemoteNotifications];
}
else
{
    // Registrar para notificações iOS anteriores ao 8
    [application registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
}
    
10.11.2014 / 00:13