1

如何在特定日期前 2 天触发 UserNotifications

我之前尝试过UserNotification,但我知道我基于时间间隔,但我不知道如何根据日期触发此通知..有人可以帮我..谢谢.. :)

4

1 回答 1

1

我想通了谢谢你的帮助。埃尔番茄

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)
}
于 2017-08-22T03:16:58.390 回答