respuesta puede invitación invitacion error enviar calendario ios iphone swift ios8 uilocalnotification

ios - invitación - no se puede enviar respuesta a la invitacion



¿Cómo cancelar una notificación local con solo presionar un botón rápidamente? (5)

Estoy programando una ubicación basada en UILocalNotification con el clic de un botón. Pero cuando intento cancelar la notificación local haciendo clic en el mismo botón otra vez, no cancela la notificación. Estoy usando UIApplication.sharedApplication().cancelLocalNotification(localNotification) para cancelar mi notificación local basada en la ubicación programada. Qué estoy haciendo mal ? aquí está mi implementación

@IBAction func setNotification(sender: UIButton!) { if sender.tag == 999 { sender.setImage(UIImage(named: "NotificationFilled")!, forState: .Normal) sender.tag = 0 regionMonitor() //function where notification get scheduled } else { sender.setImage(UIImage(named: "Notification")!, forState: .Normal) sender.tag = 999 }

¿Qué debo ingresar en el bloque else para que se cancele la notificación programada? No se pueden borrar todas las notificaciones. aquí está el código de bloque didEnterRegion donde disparo la notificación local

func locationManager(manager: CLLocationManager!, didEnterRegion region: CLRegion!) { localNotification.regionTriggersOnce = true localNotification.alertBody = "Stack Overflow is great" UIApplication.sharedApplication().scheduleLocalNotification(localNotification) NSLog("Entering region") }


Difícil de ver sin ver la implementación del código.

entonces tienes una

- IBAction methodName{ //scheduleNotification //cancelNotification }

¿Es eso correcto? Si es así, agrega un bool para

Bool didCancel; - IBAction methodName{ if didCancel == No{ //scheduleNotification didCancel = YES; }else if didCancel == YES{ //cancelNotifications didCancel = NO; }


Puede guardar un valor único para la clave en la información de usuario de su notificación local y cancelarla obteniendo la notificación local utilizando el valor de dicha clave. Pruebe esto (para el Objetivo C):

NSArray *notifArray = [[UIApplication sharedApplication] scheduledLocalNotifications]; for (int i=0; i<[notifArray count]; i++) { UILocalNotification* notif = [notifArray objectAtIndex:i]; NSDictionary *userInfoDict = notif.userInfo; NSString *uniqueKeyVal=[NSString stringWithFormat:@"%@",[userInfoDict valueForKey:@"UniqueKey"]]; if ([uniqueKeyVal isEqualToString:keyValToDelete]) { [[UIApplication sharedApplication] cancelLocalNotification:notif]; break; } }


Solución para iOS 10+ Swift 3.1

let center = UNUserNotificationCenter.current() center.removeAllDeliveredNotifications() // To remove all delivered notifications center.removeAllPendingNotificationRequests()


Para Swift 3.0 y iOS 10:

UNUserNotificationCenter.current().removeAllDeliveredNotifications()


Podría intentar eliminar todas las notificaciones si esto es aceptable en su contexto. Me gusta esto:

for notification in UIApplication.sharedApplication().scheduledLocalNotifications as! [UILocalNotification] { UIApplication.sharedApplication().cancelLocalNotification(notification) }

O como lo dice Logan:

UIApplication.sharedApplication().cancelAllLocalNotifications()

O como lo dijo Gerard Grundy para Swift 4:

UNUserNotificationCenter.current().removeAllPendingNotificat‌​ionRequests()