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

Asked

Viewed 83 times

2

I’m developing an app for different summers from 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;
  • Tested it? It worked? You can already accept and vote on any answer?

2 answers

2

Just check which method can be used on 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)];
}
  • Well, even using IF, Xcode accuses that the code is not valid, and does not allow compiling.

  • What error? and which version of Xcode you are using?

  • Xcode 6 and iPhone 4S with iOS 8.0

2


Checks which version is to be executed, and applies the code for each of the situations

    if ([[[UIDevice currentDevice] systemVersion] floatValue] < 8.0) {
     //Menor que iOS8
    }else{
    //Maior ou igual iOS8
    }
  • Thank you! I will test and as returned with the reply! rs

Browser other questions tagged

You are not signed in. Login or sign up in order to post.