【问题标题】:How To Trigger UserNotifications 2 Days Before Specific Date如何在特定日期前 2 天触发 UserNotifications
【发布时间】:2017-08-22 02:45:40
【问题描述】:

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

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

【问题讨论】:

  • 文档说... // 在 30 分钟内触发(60 秒乘以 30) let trigger = UNTimeIntervalNotificationTrigger(timeInterval: (30*60), repeats: false)

标签: ios iphone swift swift3 usernotifications


【解决方案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)
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多