gpt4 book ai didi

ios - 如何设置 UNNotificationRequest 自定义重复间隔?

转载 作者:行者123 更新时间:2023-11-28 07:24:58 24 4
gpt4 key购买 nike

我正在实现自定义重复提醒,例如默认提醒应用。这里我不介绍如何设置重复间隔,例如每第 N 天/周/月/年触发,即从现在起每 4 天/周/月/年触发通知。

这是我对 interval = 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)来实现您的自定义重新安排逻辑重复间隔,然后在每次应用运行时重新安排新通知。

关于ios - 如何设置 UNNotificationRequest 自定义重复间隔?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56852790/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com