0

I have a requirement below,

  1. First need to select date.
  2. Then app need to show the reminder options like (2 weeks before, 1 week before, 3 days before etc..,)
  3. If the selected date is two days from now then I need to disable the 2 weeks before and 1 week before option.

below is the code am using but not working,

 - (IBAction)timePicker:(id)sender {

selectedTimeRow = [sender tag];


NSDate *date2=[NSDate date];


NSDate *DaysAgo;

if (selectedTimeRow==0) {
    DaysAgo = [date2 dateByAddingTimeInterval:14*24*60*60];
    NSLog(@"14 days ago: %@", DaysAgo);

}else if (selectedTimeRow==1){
    DaysAgo = [date2 dateByAddingTimeInterval:7*24*60*60];
    NSLog(@"7 days ago: %@", DaysAgo);

}else if (selectedTimeRow==2){
    DaysAgo = [date2 dateByAddingTimeInterval:3*24*60*60];
    NSLog(@"3 days ago: %@", DaysAgo);

}else if (selectedTimeRow==3){
    DaysAgo = [date2 dateByAddingTimeInterval:1*24*60*60];
    NSLog(@"1 days ago: %@", DaysAgo);

}



NSDateFormatter *format = [[NSDateFormatter alloc] init];
format.dateFormat = @"dd/MM/yyyy";
NSString *dateNew=[format stringFromDate:DaysAgo];

UIButton *button = (UIButton *)sender;
UITableViewCell *cell = (UITableViewCell*)[button superview];

//

NSComparisonResult result = [dateNew compare:_SavedDate];
if(result == NSOrderedAscending)
{
    NSLog(@"date1 is later than date2");
  cell.userInteractionEnabled=NO;


}else if (result == NSOrderedDescending) {
    NSLog(@"date1 is earlier than date2");

       [self calltoolrBar];
    cell.userInteractionEnabled=YES;
}
else
{
    NSLog(@"date1 is equal to date2");
    [self calltoolrBar];
    cell.userInteractionEnabled=YES;
        }
}
Moin Shirazi
  • 4,372
  • 2
  • 26
  • 38

1 Answers1

-1
  1. Get two weeks ago date

    NSDate *selecteDate = YOUR_DATE; NSDate *twoWeeksAgoDate = [selecteDate dateByAddingTimeInterval:-14*24*60*60];// -14 is 14 Days(2 Weeks) before. You need to change as per your wish. NSLog(@"Two weeks ago: %@", twoWeeksAgoDate);

  2. Set local notification for twoWeeksAgo Date

    UILocalNotification *notification = [[UILocalNotification alloc]init]; notification.repeatInterval = NSDayCalendarUnit; [notification setAlertBody:@"Your Reminder"]; [notification setFireDate:twoWeeksAgoDate]; [notification setTimeZone:[NSTimeZone defaultTimeZone]]; [application setScheduledLocalNotifications:[NSArray arrayWithObject:notification]];

PREMKUMAR
  • 8,283
  • 8
  • 28
  • 51