Notificaciones Push iOS

Con la nueva versión de sistema operativo 8.0 nos hemos encontrado que ha cambiado la forma de registrar un dispositivo para que pueda recibir las notificaciones vía Push.

Para ello primero definiremos un flag con el que poder comprobar en que versión de sistema operativo está corriendo nuestra aplicación:

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

Y posteriormente añadiremos el método correspondiente para registrar el dispositivo para notificaciones Push:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Let the device know we want to receive push notifications
    if (SYSTEM_VERSION_LESS_THAN(@"8.0")) {
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
         (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
    } else {
        UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
        [[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
        [[UIApplication sharedApplication] registerForRemoteNotifications];
    }
    if (launchOptions != nil) {
        NSDictionary *dictionary = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
	if (dictionary != nil) {
            NSLog(@"Launched from push notification: %@", dictionary);
	}
    }
    return YES;
}