iOS 10 : How to repeat local notification once fired on particular date?
<p><p>我想在特定日期创建本地通知,然后在本地通知被触发后每 30 秒重复一次。这是我的代码:</p>
<pre><code>let calendar = Calendar(identifier: .gregorian)
let components = calendar.dateComponents(in: .current, from: date)
let newComponents = DateComponents(calendar: calendar, timeZone: .current, month: components.month, day: components.day, hour: components.hour, minute: components.minute)
let trigger = UNCalendarNotificationTrigger(dateMatching: newComponents, repeats: false)
let request = UNNotificationRequest(identifier: ID, content: content, trigger: trigger)
</code></pre>
<p>另一个问题:如何设置多个警报来完成相同的结果?</p>
<p>例子:</p>
<p>Alarm1:1/21/2017 @ 8:30am -> 每 30 秒重复一次</p>
<p>Alarm2:1/22/2017 @ 8:32am -> 每 30 秒重复一次
...
以此类推。</p>
<p>最好的策略是什么?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我认为您需要设置两个 <code>UNCalendarNotificationTrigger</code>。我假设您想在用户没有响应时每 30 秒重复一次。</p>
<p>一个在 <code>Alarm1: 1/21/2017 @ 8:30:00</code> 与 <code>repeat: false</code>。并使用 <code>repeat: true</code> 在 <code>1/21/2017 @ 8:30:30</code> 添加第二个 <code>UNCalendarNotificationTrigger</code>。</p>
<p>当用户响应第一个通知时,您可以删除第二个 <code>UNCalendarNotificationTrigger</code>。</p>
<p>到目前为止,没有<strong>一个</strong> <code>UserNotificationTrigger</code>允许在不同的内部重复而不用户响应通知。</p></p>
<p style="font-size: 20px;">关于iOS 10 : How to repeat local notification once fired on particular date?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/41775794/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/41775794/
</a>
</p>
页:
[1]