如何在指定日期前2天触发UserNotifications
我以前尝试过UserNotification,但我知道我是基于时间间隔的,但我不知道如何才能基于日期触发此通知。谁能帮帮我..谢谢..:)
发布于 2017-08-22 11:16:58
我想明白了,谢谢你的帮助。El西红柿
func prepareNotification() {
let content = UNMutableNotificationContent()
content.title = "Eva Reminder"
content.body = "2 Days Left Before Your Period Days."
content.sound = UNNotificationSound.default()
var components = DateComponents()
components.day = numberOfDaySelected - 2
components.hour = 7
components.minute = 0
let trigger = UNCalendarNotificationTrigger(dateMatching: components, repeats: true)
let request = UNNotificationRequest(identifier: "eva.notification", content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)
}https://stackoverflow.com/questions/45808150
复制相似问题