-1

I am developing alarm application, i want to do the repeat alarm functionality same as there in iOS Alarm Clock application, where we can select repeat option as Every Monday, Every Tuesday,... likewise.

Example: If i select only Every Monday, Every Wednesday and Every Friday then for all upcoming Monday, Wednesday and Friday the respective Alarm Notification should fire.

i tried:

  NSCalendar *calendar = [NSCalendar currentCalendar];
  NSDateComponents *componentsForFireDate = [calendar components:(NSCalendarUnitYear | NSCalendarUnitWeekOfYear |  NSCalendarUnitHour | NSCalendarUnitMinute| NSCalendarUnitSecond | NSCalendarUnitWeekday) fromDate: [dictionaryForAlarm objectForKey:kAlarmSnoozeDate]];

 NSArray *arrayForRepeatDays = @[@"2",@"4",@"6"];

 for (NSString *dayOfWeek in arrayForRepeatDays) {

     [componentsForFireDate setDay:[dayOfWeek integerValue]];
     localNotification.repeatInterval =  NSCalendarUnitWeekOfMonth;;

     [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}

but it's not getting fire on the respective days, correct me for this

Thank you in advace!

Suhas Arvind Patil
  • 1,732
  • 1
  • 19
  • 31

1 Answers1

0

I think you need to do code like this:

NSCalendar *calendar = [NSCalendar currentCalendar];
  NSDateComponents *componentsForFireDate = [calendar components:(NSCalendarUnitYear | NSCalendarUnitWeekOfYear |  NSCalendarUnitHour | NSCalendarUnitMinute| NSCalendarUnitSecond | NSCalendarUnitWeekday) fromDate: [dictionaryForAlarm objectForKey:kAlarmSnoozeDate]];

 NSArray *arrayForRepeatDays = @[@"2",@"4",@"6"];

 for (NSString *dayOfWeek in arrayForRepeatDays) {

     [componentsForFireDate setWeekday: [dayOfWeek integerValue]] 
     [componentsForFireDate setHour: 10] ; // here you can set hr as per you need
     localNotification.repeatInterval =  NSWeekCalendarUnit;
     localNotification.fireDate=[calendar dateFromComponents:componentsForFireDate];
     [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}

I Guess this two like make this working:

[componentsForFireDate setWeekday: [dayOfWeek integerValue]] 
localNotification.repeatInterval =  NSWeekCalendarUnit;
Nitin Gohel
  • 49,482
  • 17
  • 105
  • 144