我如何在每个星期一使用闹钟?

时间:2014-04-08 07:15:05

标签: nsdate uilocalnotification

NSDate *today = [NSDate date];
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
[gregorian setLocale:[NSLocale currentLocale]];

NSDateComponents *nowComponents = [gregorian components:NSYearCalendarUnit | NSWeekCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit fromDate:today];

[nowComponents setWeekday:2]; //Monday
[nowComponents setWeek: [nowComponents week] + 1]; //Next week
[nowComponents setHour:8]; //8a.m.
[nowComponents setMinute:0];
[nowComponents setSecond:0];

NSDate *timeDate = [gregorian dateFromComponents:nowComponents];



localNotif.fireDate = timeDate;
localNotif.timeZone = [NSTimeZone defaultTimeZone];
localNotif.repeatInterval = NSWeekdayCalendarUnit;


localNotif.alertBody = [NSString stringWithFormat:@"nowtime %@ == %@ %@ %@ %@ ",date,saveDataWeekday,saveDataAmPm,saveDataHour,saveDataMinute];

localNotif.alertAction = @"info";
localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.applicationIconBadgeNumber = 1;


[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];

警报在一周中的指定日期无效

我想设置 例如 - >每个星期一或每个星期五或每天

0 个答案:

没有答案