¿Cómo cancelar una Notificación local con solo presionar un botón?
Estoy programando una ubicación basadaUILocalNotification
con el clic de un botón Pero cuando trato de cancelar la Notificación local haciendo clic nuevamente en el mismo botón, no cancela la notificación. estoy usandoUIApplication.sharedApplication().cancelLocalNotification(localNotification)
para cancelar mi ubicación programada basada en notificaciones locales. 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á eldidEnterRegion
bloquee el código donde active 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")
}