首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在指定日期前2天触发UserNotifications

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

Stack Overflow用户
提问于 2017-08-22 10:45:41
回答 1查看 533关注 0票数 1

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

我以前尝试过UserNotification,但我知道我是基于时间间隔的,但我不知道如何才能基于日期触发此通知。谁能帮帮我..谢谢..:)

EN

回答 1

Stack Overflow用户

发布于 2017-08-22 11:16:58

我想明白了,谢谢你的帮助。El西红柿

代码语言:javascript
复制
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)
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45808150

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档