ios - 如何设置本地通知在(早上 8 :00AM and Evening 8:00PM) in ios?
<p><p>目前我正在使用 Xcode 7.2</p>
<p>我有这样的要求:实际上我想在<strong>上午 8:00 和晚上 8:00 安排每日通知(每天仅两次)。</strong></p>
<p>我不熟悉本地通知的使用。我做了一些研发我发现一些链接也喜欢:<a href="https://stackoverflow.com/questions/19762936/daily-uilocalnotification-firing-more-than-once" rel="noreferrer noopener nofollow">Daily UILocalNotification firing more than once</a>
.但我无法解决我的问题....</p>
<p>如果应用程序处于<strong>非事件/事件/后台/暂停</strong>,我需要向特定用户显示本地通知。</p>
<p>我该如何克服这个问题?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p><strong>早上 8:00 的通知</strong></p>
<pre><code>UILocalNotification *localNotif1 = [ init];
localNotif1.alertBody = @"Morning 8:00 AM";
NSDateComponents *components1 = [ components:(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitWeekOfMonth) fromDate:];
;
;
localNotif1.fireDate = [ dateFromComponents:components1];
;
[ scheduleLocalNotification:localNotif1];
</code></pre>
<p><strong>晚上 8:00 的通知</strong></p>
<pre><code>UILocalNotification *localNotif2 = [ init];
localNotif2.alertBody = @"Evening 8:00 PM";
NSDateComponents *components2 = [ components:(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitWeekOfMonth) fromDate:];
;
;
localNotif2.fireDate = [ dateFromComponents:components2];
;
[ scheduleLocalNotification:localNotif2];
</code></pre></p>
<p style="font-size: 20px;">关于ios - 如何设置本地通知在(早上 8 :00AM and Evening 8:00PM) in ios?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/36128366/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/36128366/
</a>
</p>
页:
[1]