如果是这样,请帮我提供一个示例快速代码.
@IBAction func setNotification(sender: UIbutton!) { cell = tableVIEw.cellForRowAtIndexPath(NSIndexPath(forRow: sender.tag,inSection: 0)) as! CustomtableVIEwCell if sender.selected { sender.selected = false }else {currentRegion = CLCircularRegion(center: CLLocationCoordinate2D(latitude: latitude,longitude:longitude),radius: radius,IDentifIEr: IDentifIEr)regionMonitor() manager.stopUpdatingLocation() sender.selected = true } }
dIDEnterRegion()的代码
func locationManager(manager: CLLocationManager!,dIDEnterRegion region: CLRegion!) { localnotification.regionTriggersOnce = true localnotification.alertbody = "you have reached" UIApplication.sharedApplication().schedulelocalnotification(localnotification) NSLog("Entering region") }解决方法 您可以在userInfo中为每个UIlocalnotification保存唯一标识符,然后遍历它们以查找唯一ID并将其删除:
var app:UIApplication = UIApplication.shared if let localnotifications = app.scheduledlocalnotifications { for oneEvent in localnotifications { var notification = oneEvent as UIlocalnotification if let userInfoCurrent = notification.userInfo as? [String:AnyObject],let uID = userInfoCurrent["uID"] as? String { if uID == uIDtodelete { //Cancelling local notification app.cancellocalnotification(notification) break } } } }
更新为Swift 3并进行了改进以防止无崩溃
总结以上是内存溢出为你收集整理的ios – 如何在swift中取消特定的UILocalNotification?全部内容,希望文章能够帮你解决ios – 如何在swift中取消特定的UILocalNotification?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)