我怎样才能让我的应用程序能够每天以自定义的时间间隔发射本地通知,但只在分配的时间内发射,例如:从晚上10:00到20:00?
现在我只实现了自定义间隔的重复通知。
func beginNotifications(_ config: UserConfig) {
let interval = config.notificationInterval
let center = UNUserNotificationCenter.current()
center.removeAllPendingNotificationRequests()
let content = UNMutableNotificationContent()
content.title = "Content title"
content.subtitle = "Content body"
content.sound = UNNotificationSound.default
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: interval, repeats: true)
let request = UNNotificationRequest(identifier: "notification", content: content, trigger: trigger)
center.add(request)
}
到目前为止,我只想到了一个解决方案--使用Timer制作两个独立的方法,每天启动和停止通知功能,并为应用程序启用后台模式。