내 앱에는 LocalNotification이 있습니다. 메신저 DatePicker에서 발사 시간을 얻고 LocalNotification이 특정 시간 (UIPickerView에서 가져옴)과 토요일을 제외한 모든 평일에 모든 주를 시작하고 싶습니다.
편집하다
UIDatePicker *picker = [[UIDatePicker alloc]init];
[picker setTag:kDatePickerTag];
for (int i = 0; i < 7; i++) {
NSDate *today = [NSDate date];
NSCalendar *gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDate *scheduleDate = [**picker.date** dateByAddingTimeInterval:(i * 24.0f * 3600.0f)];
NSDateComponents *componentsForEachDay = [gregorianCalendar components:NSWeekdayCalendarUnit fromDate:scheduleDate];
if (componentsForEachDay.weekday != 7) { // To skip Saturday
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.repeatInterval = NSWeekCalendarUnit;
localNotification.fireDate = picker.date;
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.alertBody = @"test message";
localNotification.soundName = UILocalNotificationDefaultSoundName;
localNotification.applicationIconBadgeNumber = 1;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
나는 지금 까지이 코드를 가지고 있지만 이제 발사 시간을 설정해야하며 시간을 제공하는 picker.date 사이에 병합하는 방법을 모르겠습니다. 나는 둘 다 동일한 NSDate 객체가 필요합니다. 어떤 아이디어?
토요일을 건너 뛰려면 나머지 6 일마다 알림을 설정하고 주 단위로 반복해야합니다.
NSCalendar *gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
for (int i = 0; i < 7; i++) {
NSDate *scheduleDate = [firstScheduledDate dateByAddingTimeInterval:(i * 24.0f * 3600.0f)];
NSDateComponents *componentsForEachDay = [gregorianCalendar components:NSWeekdayCalendarUnit fromDate:scheduleDate];
if (componentsForEachDay.weekday != 7) { // To skip Saturday
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.repeatInterval = NSWeekCalendarUnit;
localNotification.fireDate = FIRE_DATE;
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.alertBody = YOUR_NOTIFICATION_MESSAGE;
localNotification.soundName = UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다