我需要设置UILocalNotification,我只需要从DatePicker获取小时和分钟,并需要设置特定日期 (如:星期一)并在每个星期一重复.
我有两个问题:
第一 ; 是否可以在日期选择器的日期部分仅显示"日期名称",如"星期日"?
第二个问题是; 如果我想设置本地通知的具体日期,那么正确的代码是什么?
谢谢你的答案,下面是我的代码;
-(IBAction) alarmButton:(id)sender {
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
dateFormatter.timeZone = [NSTimeZone defaultTimeZone];
dateFormatter.timeStyle = NSDateFormatterShortStyle;
dateFormatter.dateStyle = NSDateFormatterShortStyle;
NSString *dateTimeString = [dateFormatter stringFromDate: dateTimePickerSet1.date];
NSLog ( @"Alarm Set :%@" , dateTimeString);
[self scheduleLocalNotificationWithDate1: dateTimePickerSet1.date];
}
-(void)scheduleLocalNotificationWithDate1:(NSDate *)fireDate {
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.fireDate = fireDate;
notification.alertBody = @"Alarm Set !";
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
Run Code Online (Sandbox Code Playgroud)