Iphone 带有NSDate的UILocalNotification
我阅读了UILocalNotification的文档,示例显示了如何使用NSDateComponents,然后设置周、日、月等来安排通知。我基本上是想做一些类似于闹钟的事情,每天在特定的时间重复。我在UIPickerView中有一个时间,我从该时间为我的对象创建了一个NSDate。所以我抓紧时间,试着像这样安排通知:Iphone 带有NSDate的UILocalNotification,iphone,uilocalnotification,Iphone,Uilocalnotification,我阅读了UILocalNotification的文档,示例显示了如何使用NSDateComponents,然后设置周、日、月等来安排通知。我基本上是想做一些类似于闹钟的事情,每天在特定的时间重复。我在UIPickerView中有一个时间,我从该时间为我的对象创建了一个NSDate。所以我抓紧时间,试着像这样安排通知: NSDate *date = [dateFormatter dateFromString:s]; NSCalendar *calender = [NSCalenda
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];
我可以这样做吗?或者我必须使用NSDATE组件。我的代码目前没有发出通知,我想知道是否有可能以这种方式发出通知,或者是否必须使用NSDateComponents
此外,如果我必须使用NSDateComponents,那么我如何获取当前日期,以便设置当天的警报,并且我假设从那里repeatInterval将在接下来的几天生效
非常感谢 只要firedate是有效的NSDate,就会触发通知。这是我在应用程序时间中使用的代码
UILocalNotification *localNotification = [[UILocalNotification alloc] init]];
localNotification.fireDate = [NSDate date];
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.alertBody = @"some string";
localNotification.repeatInterval = NSWeekCalendarUnit;
localNotification.repeatCalendar = [NSCalendar currentCalendar];
localNotification.soundName = UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
检查您传递给firedate的日期是否有效。我不确定您使用的时区重复码是否需要?这可能会引起问题