tutorial react notification ios xcode apple-push-notifications ios8 xcode6

react - push notifications ios swift 4



Construir para iOS si registerForRemoteNotificationTypes: no es compatible con iOS 8.0 y posterior (7)

Según la documentación de Apple registerForRemoteNotificationTypes: está en desuso en iOS 8, en su lugar puede usar registerForRemoteNotifications y registerUserNotificationSettings:

Xcode 6 beta e iOS 8 beta son softwar de prelanzamiento. Las versiones Beta son solo para desarrollo y prueba. Deben crearse nuevas aplicaciones y actualizaciones de aplicaciones con las versiones de lanzamiento de Xcode e iOS para enviar a App Store.

Si hay cambios importantes con la forma en que los dispositivos se registran para las notificaciones, y no podemos usar registerForRemoteNotificationTypes: ¿cómo podemos construir una nueva versión de la aplicación para admitir iOS 8 si no podemos usar Xcode 6 beta? ¿Tendremos que crear y enviar el día en que se lanza la versión Xcode 6 GM para que nuestros usuarios continúen recibiendo notificaciones push?


iOS 8 ha cambiado el registro de notificaciones. Por lo tanto, debe verificar la versión del dispositivo y luego debe registrar la configuración de las notificaciones (consulte este enlace). Intento este código en Xcode 6 y me funcionó.

- (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; }


Puede considerar usar respondsToSelector en lugar de verificar la versión del sistema:

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)]; }


escriba este código en la función AppDelegate didFinishLaunchingWithOptions

if([[UIApplication sharedApplication] respondsToSelector:@selector(registerForRemoteNotifications)]) { UIUserNotificationType types = UIUserNotificationTypeAlert | UIUserNotificationTypeSound | UIUserNotificationTypeBadge; UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types categories:nil]; [[UIApplication sharedApplication] registerUserNotificationSettings:settings]; [[UIApplication sharedApplication] registerForRemoteNotifications]; } else { UIRemoteNotificationType types = UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeBadge; [[UIApplication sharedApplication] registerForRemoteNotificationTypes:types]; } [self.window makeKeyAndVisible]; return YES;


Puedes usar esto,

if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)]) { // for iOS 8 [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]]; [application registerForRemoteNotifications]; } else { // for iOS < 8 [application registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)]; } // RESET THE BADGE COUNT application.applicationIconBadgeNumber = 0;


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)]; }


#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