0
我阅读了UILocalNotification的文档,该示例显示使用NSDateComponents,然后设置星期,日期,月份等,以安排通知。我基本上是想做一些类似闹钟的事情,在特定的时间每天重复一次。我有一段时间在UIPickerView,并从那时为我的对象创建一个NSDate。所以我抓紧时间,我试图安排通知如下:使用NSDate的UILocalNotification
NSDate *date = [dateFormatter dateFromString:s];
NSCalendar *calender = [NSCalendar currentCalendar];
NSLog(@"%@", s);
UILocalNotification *note = [[UILocalNotification alloc] init];
note.alertAction = alarm.name;
note.alertBody = alarm.note;
note.fireDate = date;
note.timeZone = [[NSCalendar currentCalendar] timeZone];
note.repeatInterval = NSDayCalendarUnit;
note.timeZone = [NSTimeZone systemTimeZone];
[[UIApplication sharedApplication] scheduleLocalNotification:note];
我可以这样做吗?或者我必须使用NSDateComponents。我的代码目前不会触发通知,我想知道是否可以通过这种方式触发通知,或者如果您必须使用NSDateComponents。
另外,如果我确实需要使用NSDateComponents,那么我该如何才能获得当天的日期,以便我可以设置当天的闹钟,并且我假设从那里repeatInterval将在接下来的日子生效。
非常感谢!