ios - 具有每周重复和特定开始日期的通知
<p><p>我可以将 UNNotification 设置为在特定日期/时间触发,就像这样</p>
<pre><code>let components = Calendar.current.dateComponents([.year, .month, .day, .hour, .minute], from: fireTime)
let trigger = UNCalendarNotificationTrigger(dateMatching: components, repeats: false)
</code></pre>
<p>我可以设置一个在一周中特定日期的特定时间触发,每周,就像这样</p>
<pre><code>var components = Calendar.current.dateComponents([.weekday], from: nextMondayDate)
components.setValue(10, for: .hour)
let trigger = UNCalendarNotificationTrigger.init(dateMatching: triggerComps, repeats: true)
</code></pre>
<p>但是有什么方法可以设置 UNNotification 在特定日期和时间触发,然后每周在该工作日和时间重复?</p>
<p>具体来说,我想将通知设置为每周一上午 10 点触发<strong>除了</strong>下周一。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>如果您只想跳过<strong>仅</strong>下周一,您可以计算下周一的下一个日期并在组件中设置 nextMondayDate 的位置保持其余设置不变,如重复 true .</p></p>
<p style="font-size: 20px;">关于ios - 具有每周重复和特定开始日期的通知,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/48540447/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/48540447/
</a>
</p>
页:
[1]