我正在处理 loacl 通知通知成功。但我不想为来自选择器的通知设置触发时间我想设置用户想要的通知触发时间。我已经给文本字段输入时间,并希望根据用户时间设置 firedate。
假设用户在下午 1 点输入,然后通知在今天下午 1 点到来
下面是我的代码——
NSCalendar *calendar = [NSCalendar currentCalendar]; // gets default calendar
NSDateComponents *components = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit) fromDate:[NSDate date]]; // gets the year, month, day,hour and minutesfor today's date
[components setHour:txtStartTime.text];
// [components setMinute:12];
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = [calendar dateFromComponents:components];
localNotification.timeZone = [NSTimeZone localTimeZone];
localNotification.alertBody = txtSubjectName.text;
localNotification.alertAction = @"Lecture Notification";
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
[self dismissViewControllerAnimated:YES completion:nil];