我想从特定时间开始每 8 小时发送一次本地通知。例如,现在我们是早上 10 点,但我希望你从 12 点开始每 8 小时通知我一次,我该怎么做。
我有这个代码:
let content: UNMutableNotificationContent = UNMutableNotificationContent()
content.title = "Alert!"
content.body = "Alert"
content.categoryIdentifier = "alarm"
let request = UNNotificationRequest(
identifier: "AA",
content: content,
trigger: UNTimeIntervalNotificationTrigger(timeInterval: 8*3600, repeats: false)
)
let action = UNNotificationAction(identifier: "remindLater", title: "remind_me_later".localized(), options: [])
let category = UNNotificationCategory(identifier:"pill-alarm", actions: [action], intentIdentifiers: [], options: [])
UNUserNotificationCenter.current().setNotificationCategories([category])
UNUserNotificationCenter.current().add(request)