tutorial remote notification ios iphone ipad push-notification apple-push-notifications

remote - Push Notification ON u OFF Checking en iOS



push notifications ios swift tutorial (4)

Quiero marcar "Opción de notificación push" en el dispositivo iOS, en cualquier momento si la aplicación se está ejecutando (u ACTIVADA desde el modo de reanudación). Utilizo el siguiente código para verificar, si la opción está desactivada:

-(void)PushNotificationServiceChecking { UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes]; if (types == UIRemoteNotificationTypeNone) { NSString *msg = @"Please press ON to enable Push Notification"; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Push Notification Service Disable" message:msg delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"ON", nil]; alert.tag = 2; [alert show]; } }

Luego uso el siguiente código para ir a la "pestaña Configuración >> Centro de notificaciones", para que el usuario pueda hacerlo manualmente:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { if (alertView.tag == 2) { if (buttonIndex == 0) { // this is the cancel button } else if (buttonIndex == 1) { [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound|UIRemoteNotificationTypeAlert)]; } } }

Pero ahora, el problema al que me enfrento es que solo aparece la primera vez después de iniciar la aplicación. Funciona como yo quiero. Pero después de eso, si desactivo la "Opción de notificación push" de "configuración" no aparece ningún "Mensaje de alerta".


En iOS 8 ahora puedes usar:

[[UIApplication sharedApplication] isRegisteredForRemoteNotifications];

Y para comprobar cómo están configurados los ajustes, puedes usar:

[[UIApplication sharedApplication] currentUserNotificationSettings];


Es un trabajo para mí. ¡Espero que esto ayude! :RE

#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending) if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")){ UIUserNotificationType type = [[[UIApplication sharedApplication] currentUserNotificationSettings] types]; if (type == UIUserNotificationTypeNone){ ALERT_WITH_TITLE(@"", kMessageNotificationTurnOnRequire); } } else { UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes]; if (types == UIRemoteNotificationTypeNone) { ALERT_WITH_TITLE(@"", kMessageNotificationTurnOnRequire); } }


Si la aplicación una vez se registró con el registerForRemoteNotification , puede deshabilitarlo y habilitarlo. Una vez que lo deshabilites y estés a punto de volver a registrarte con él, esto habilitará el registerForRemoteNotification , sin Popup para una alerta.

Nota técnica TN2265: Solución de problemas de notificaciones automáticas

La primera vez que una aplicación habilitada para push se registra para notificaciones push, iOS pregunta al usuario si desea recibir notificaciones para esa aplicación. Una vez que el usuario responde a esta alerta, no se vuelve a presentar a menos que el dispositivo se restaure o la aplicación se haya desinstalado durante al menos un día.

Si desea simular una ejecución por primera vez de su aplicación, puede dejar la aplicación desinstalada por un día. Puede lograr esto último sin tener que esperar un día si el reloj del sistema avanza un día o más, apaga el dispositivo por completo y luego vuelve a encenderlo.

Para más información: INFO && Info 2

Editar : Para checking with alert enable -

utilizar

if (types & UIRemoteNotificationTypeAlert){}

en lugar de

if (types == UIRemoteNotificationTypeNone){}

Edición: la última actualización del documento para iOS 8 o posterior , se puede consultar a través de:

- (BOOL)isRegisteredForRemoteNotifications


NSString *iOSversion = [[UIDevice currentDevice] systemVersion]; NSString *prefix = [[iOSversion componentsSeparatedByString:@"."] firstObject]; float versionVal = [prefix floatValue]; if (versionVal >= 8) { if ([[UIApplication sharedApplication] currentUserNotificationSettings].types != UIUserNotificationTypeNone) { NSLog(@" Push Notification ON"); } else { NSString *msg = @"Please press ON to enable Push Notification"; UIAlertView *alert_push = [[UIAlertView alloc] initWithTitle:@"Push Notification Service Disable" message:msg delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Setting", nil]; alert_push.tag = 2; [alert_push show]; NSLog(@" Push Notification OFF"); } } else { UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes]; if (types != UIRemoteNotificationTypeNone) { NSLog(@" Push Notification ON"); } else { NSString *msg = @"Please press ON to enable Push Notification"; UIAlertView *alert_push = [[UIAlertView alloc] initWithTitle:@"Push Notification Service Disable" message:msg delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Setting", nil]; alert_push.tag = 2; [alert_push show]; NSLog(@" Push Notification OFF"); } }