如何在给定的时隙中每隔X分钟发送一次用户通知

时间:2020-08-31 05:54:13

标签: swift nstimer uilocalnotification

我正在制作一个具有在给定时间段(例如,上午8点至晚上10点)之间每30分钟发送一条消息的功能的应用。现在,我有了用于请求许可并定期发送通知的代码,但是我无法弄清楚如何在特定时间段内包含这些通知。


let center = UNUserNotificationCenter.current()

    let content = UNMutableNotificationContent()
    content.title = "Content title"
    content.body = "My content body."
    content.categoryIdentifier = "alarm"
    content.userInfo = ["customData": "fizzbuzz"]
    content.sound = UNNotificationSound.default

    let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 1,800, repeats: true)

   let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger)
    center.add(request)

谢谢

0 个答案:

没有答案
相关问题