我正在使用一个按钮来安排基于位置的UILocalNotification
。但是,当我尝试通过再次单击相同的按钮来取消本地通知时,它没有被取消。
我正在使用UIApplication.sharedApplication().cancelLocalNotification(localNotification)
来取消我已安排的基于位置的本地通知。
我做错了什么吗?
这是我的实现:
@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 }
我应该在else块中输入什么,以便取消预定的通知。无法清除所有通知。
以下是我的didEnterRegion
代码块,我在其中触发本地通知。
func locationManager(manager: CLLocationManager!, didEnterRegion region: CLRegion!) {
localNotification.regionTriggersOnce = true
localNotification.alertBody = "Stack Overflow is great"
UIApplication.sharedApplication().scheduleLocalNotification(localNotification)
NSLog("Entering region")
}
UIApplication.sharedApplication().cancelAllLocalNotifications()
。 - LoganUIApplication.shared.cancelAllLocalNotifications()
在iOS 10.0中已被弃用。我们需要使用用户通知框架。 - Arun Reddy