我正在開發應用程序,其中用戶可以爲每天的本地通知設置時間,然後我可以選擇啓用或禁用這些通知。我的問題如何禁用/取消已設置的通知?UserNotifications cancel,swift3
在這裏,在這個國際單項體育聯合會,我需要取消通知符
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if (indexPath as NSIndexPath).row == 1 && switchiBtn.isOn == false {
return 0.0
}
if (indexPath as NSIndexPath).row == 2 {
if switchiBtn.isOn == false || dpVisible == true {
return 0.0
}
return 216.0
}
if (indexPath as NSIndexPath).row == 3 {
if switchiBtn.isOn == false || dpVisible == true {
return 0.0
}
return 44
}
return 50.0
}
這裏一個是進度和按鈕的功能在那裏我設置通知符。
func scheduleNotif(date: DateComponents, completion: @escaping (_ Success: Bool) ->()) {
let notif = UNMutableNotificationContent()
notif.title = "Your quote for today is ready."
notif.body = "Click here to open an app."
let dateTrigger = UNCalendarNotificationTrigger(dateMatching: date, repeats: true)
let request = UNNotificationRequest(identifier: "myNotif", content: notif, trigger: dateTrigger)
UNUserNotificationCenter.current().add(request, withCompletionHandler: { error in
if error != nil {
print(error)
completion(false)
} else {
completion(true)
}
})
}
@IBAction func setACTION(_ sender: AnyObject) {
let hour = datePicker.calendar.component(.hour, from: datePicker.date)
let minute = datePicker.calendar.component(.minute, from: datePicker.date)
var dateComponents = DateComponents()
dateComponents.hour = hour
dateComponents.minute = minute
print(dateComponents)
scheduleNotif(date: dateComponents, completion: { success in
if success {
print("SUCCESS")
} else {
print("ERROR")
}
})
謝謝。
嗨,你可以檢查我的答案。隨意評論任何有關這個問題或我的回答的討論 – KrishnaCA