如何解决如何在 Swift 中使用 removeAllPendingNotificationRequests
我尝试在 SwiftUI 中使用“removeAllPendingNotificationRequest()”中断计划的通知,但我不知道如何操作。我正在计划多个通知,并想通过一个按钮取消它们。
谢谢
let content2 = UNMutableNotificationContent()
content2.title = "Dies ist deine Persönliche Erinnerung,"
content.subtitle = "Deine Schulsachen zu packen."
content2.body = "Du hast morgen: \(Fächer[Dienstag1B]) \(Fächer[Dienstag2B]) \(Fächer[Dienstag3B]) \(Fächer[Dienstag4B]) \(Fächer[Dienstag5B]) \(Fächer[Dienstag6B])"
content2.sound = UNNotificationSound.default
var dateComponents2 = DateComponents()
dateComponents2.calendar = Calendar.current
dateComponents2.weekday = 2 //Montag-> Dienstag
dateComponents2.hour = 8
dateComponents2.minute = 45
let trigger2 = UNCalendarNotificationTrigger(dateMatching: dateComponents2,repeats: true)
let uuid2 = UUID().uuidString
let request2 = UNNotificationRequest(identifier: uuid2,content: content2,trigger: trigger2)
let notificationCenter2 = UNUserNotificationCenter.current()
notificationCenter2.add(request2)
}
}
Button(action: UNUserNotificationCenter.current().removeAllPendingNotificationRequest(),label: {
Text("Cancel Notifications")
})
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。