传递 kCFCalendarUnitWeekday 的值
我想在特定的一天设置闹钟。我不明白如何设置 kCFCalendarUnitWeekday
的值。这是我的代码:
NSDateComponents *components = [[NSDateComponents alloc] init];
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
return;
localNotif.fireDate = selected;
localNotif.timeZone = [NSTimeZone defaultTimeZone];
localNotif.repeatCalendar = [NSCalendar currentCalendar];
if (isSun) {
[components setWeekday:1];
[localNotif setRepeatInterval:(NSInteger)components];
}
if (isMon) {
[components setWeekday:2];
[localNotif setRepeatInterval:(NSInteger)components];
}
谢谢。
I want to set an alarm on a particular day. I don't understand how to set the value of kCFCalendarUnitWeekday
. Here is my code:
NSDateComponents *components = [[NSDateComponents alloc] init];
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
return;
localNotif.fireDate = selected;
localNotif.timeZone = [NSTimeZone defaultTimeZone];
localNotif.repeatCalendar = [NSCalendar currentCalendar];
if (isSun) {
[components setWeekday:1];
[localNotif setRepeatInterval:(NSInteger)components];
}
if (isMon) {
[components setWeekday:2];
[localNotif setRepeatInterval:(NSInteger)components];
}
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,这里有一些代码可以让您朝着正确的方向前进:
您仍然必须找出 newDate 是否是过去的,因此它不会触发。
您实际上已准备好代码:
围绕此代码片段创建一个方法,并使用参数传递日期,以便您可以重用它。您只需输入一个日期,该日期应该是第一次火灾日期,并且每周都会重复。您只需传入周日或周三的日期即可。
您可以这样设置重复间隔:
repeatCalender 属性的类型为 NSCalendarUnit 这是一个枚举。
Ok here is some code to get you in the right direction:
You still have to find out whether the newDate is in the past, so it won't fire.
You actually have your code ready:
Create a method around this snippet and pass the date with a parameter so you can reuse it. You only have to put in a date which should be the first fire date and it'll repeat every week. You just have to pass in a date on a Sunday or Wednesday.
You set a repeat interval like this:
The repeatCalender property is of type NSCalendarUnit which is an enum.