![](/img/trans.png)
[英]How to Set repeat interval as well as fire date in UNNotificationRequest
[英]How to set UNNotificationRequest's custom repeat interval?
我正在实现自定义重复提醒,例如默认提醒应用程序。 在这里,我不介绍如何设置重复间隔,例如从现在开始每隔N日,每周,每月,每年第4天触发一次,即触发通知。
这是我的间隔= 1的实现
if type == .daily{
dateComponents = Calendar.current.dateComponents([.hour, .minute], from: Date())
}else if type == .weekly{
dateComponents = Calendar.current.dateComponents([.hour, .minute,.weekday], from: Date())
}else if type == .monthly{
dateComponents = Calendar.current.dateComponents([.day,.hour, .minute], from: Date())
}else if type == .yearly{
dateComponents = Calendar.current.dateComponents([.hour, .minute,.day,.month], from: Date())
}
不幸的是,UNNotificationRequest没有界面来设置本地通知的自定义重复间隔。
似乎没有一个稳定的解决方案可以解决您的问题,但是作为一种解决方法,您可以尝试根据重复间隔请求多个本地通知(使用UNTimeIntervalNotificationTrigger
),然后在每次应用开始运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.