ios - 为什么通知适用于 NSHourCalendarUnit 但不适用于 NSWeekCalendarUnit?
<p><p>我不明白为什么 <code>LocalNotification</code> 可以完美地与 NSHourCalendarUnit 一起工作,但永远不会与 <code>NSWeekCalendarUnit</code> 和 <code>NSDayCalendarUnit</code> 一起工作,尽管它显示了正确的时间日志!!当设置 <code>weekday</code> 我需要它来触发时,一定有什么我错过了。它会是什么?</p>
<p>请查看我的代码日志出来,以便您可以指导我正在做的错误:</p>
<pre><code>-(void) Monday { // 9th Notification Every 1:35
NSCalendar *calendar = ;
calendar.timeZone = ;
NSDateComponents *components = ];
components.weekday = 2;
components.hour = 10;
components.minute = 56;
components.second = 35;
NSDate *fire = ;
NSLog(@"The Fire Day is:: %@", fire);
UILocalNotification *notif = [init] ;
if (notif == nil)
return;
notif.fireDate = fire;
notif.repeatInterval= NSWeekCalendarUnit ;
notif.soundName = @"ring.wav";
notif.alertBody = ;
[ scheduleLocalNotification:notif] ;
NSLog(@"*****NEW LOG Notification Details*****%@", notif);
}
</code></pre>
<p>这是日志:</p>
<pre><code>2014-01-20 10:09:12.935 daily notification test The Fire Day is:: 2014-01-20 10:10:35 +0000
</code></pre>
<p>*<strong><em>日志更新:</em>*</strong></p>
<pre><code>2014-01-20 10:56:21.694 daily notification test The Fire Day is:: 2014-01-20 10:56:35 +0000
2014-01-20 10:56:21.697 daily notification test *****NEW LOG Notification Details*****<UIConcreteLocalNotification: 0x7180360>{fire date = Monday, January 20, 2014, 11:56:35 AM Central European Standard Time, time zone = (null), repeat interval = NSWeekCalendarUnit, repeat count = UILocalNotificationInfiniteRepeatCount, next fire date = Monday, January 20, 2014, 11:56:35 AM Central European Standard Time, user info = (null)}
.
</code></pre>
<p>2014-01-20 10:56:21.694 每日通知测试 The Fire Day is::2014-01-20 10:56:35 +0000
2014-01-20 10:56:21.697 每日通知测试 <strong>**<em>新日志通知详细信息</em>**</strong>{发布日期 = 2014 年 1 月 20 日星期一, 11:56:35 AM 中欧标准时间,时区 = (null),重复间隔 = NSWeekCalendarUnit,重复计数 = UILocalNotificationInfiniteRepeatCount,下一个触发日期 = 2014 年 1 月 20 日,星期一,11:56:35 AM 中欧标准时间, 用户信息 = (null)}</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>只需替换</p>
<pre><code>notif.repeatInterval= NSHourCalendarUnit ;
</code></pre>
<p>与</p>
<pre><code>notif.repeatInterval= NSWeekCalendarUnit;
</code></pre>
<p>编辑</p>
<p>现在试试这个,它可能会有所帮助</p>
<pre><code>NSCalendar *gregorian1 = [ initWithCalendarIdentifier:NSGregorianCalendar];
];
NSDateComponents *nowComponents = ];
; //Monday
+ 1]; //Next week
; //8a.m.
;
;
NSDate *beginningOfWeek = ;
</code></pre></p>
<p style="font-size: 20px;">关于ios - 为什么通知适用于 NSHourCalendarUnit 但不适用于 NSWeekCalendarUnit?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/21230024/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/21230024/
</a>
</p>
页:
[1]