ios - 如何每天显示一次警报
<p><p>我正在尝试弄清楚如何在用户达到目标后弹出警报。但是,我只希望它在触发后每天显示一次。提前致歉。如果我的逻辑不适合解决这个问题。</p>
<pre><code>// Check to see if hydration goal has been reached
if (waterCups >= dailyHydrationGoal) {
// User has reached goal
if (alert has not been fired yet today) {
// alert pop up you reached your goal!
}
}
</code></pre>
<p>我将如何确保它每天只启动一次?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您可以使用 <a href="https://developer.apple.com/documentation/foundation/nscalendar/1417149-isdateintoday?language=objc" rel="noreferrer noopener nofollow"><code>isDateInToday:</code></a>检查给定日期是否在“今天”的方法。</p>
<pre><code>NSDate *lastAlertDate = (NSDate *)[ objectForKey:@"lastAlertDate"];
if(![ isDateInToday:lastAlertDate]){
//Show alert
NSDate *today= ;
[ setObject:today forKey:@"lastAlertDate"];
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 如何每天显示一次警报,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/44853326/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/44853326/
</a>
</p>
页:
[1]