首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何设置UNNotificationRequest的自定义重复间隔?

如何设置UNNotificationRequest的自定义重复间隔?
EN

Stack Overflow用户
提问于 2019-07-02 20:43:53
回答 1查看 174关注 0票数 1

我正在实现一个自定义的重复提醒,如默认提醒应用程序。在这里,我不知道如何设置每N天/周/月/年的重复间隔like Trigger,即,从现在起每第4天/周/月/年触发通知。

下面是我对interval =1的实现

代码语言:javascript
复制
    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())
    }
EN

回答 1

Stack Overflow用户

发布于 2019-07-02 22:11:42

不幸的是,UNNotificationRequest没有为本地通知设置自定义重复间隔的接口。

看起来,你的问题没有稳定的工作解决方案,但作为一种变通方法,你可以尝试通过基于重复间隔请求多个本地通知(使用UNTimeIntervalNotificationTrigger),然后在每次应用程序开始运行时重新安排新的通知,来实现自定义的重新安排逻辑。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56852790

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档