sorry for the question.I have to save the time when the button is clicked for
the first time and then compare the time with the future time and if it is greater than or
equal to the same time I have to fire a method or else an alert.
Here is the code.
-(IBAction)checkInButtonClicked
{
now = [NSDate date];
[[NSUserDefaults standardUserDefaults]setObject:now forKey:@"theFutureDate"];
NSTimeInterval timeToAddInDays = 60 * 60 * 24;
theFutureDate = [now dateByAddingTimeInterval:timeToAddInDays];
switch ([now compare:theFutureDate]){
case NSOrderedAscending:{
NSLog(@"NSOrderedAscending");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:
[NSString stringWithFormat:@"Oops! The Check In will activate after 24Hrs"]
delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil ];
[alert show];
}
break;
case NSOrderedSame:{
NSLog(@"NSOrderedSame");
[self insertPoints];
}
break;
case NSOrderedDescending:{
NSLog(@"NSOrderedDescending");
}
break;
}
}
But this code is not working exactly.Can anyone please help me out.
Thanks in advance.
The problem is that you’re comparing always
nowwith a future date. That comparison has always the same result.If I understood correctly you want exactly the other way around. You must compare
nowwith the first time the user clicked the button. So you set the date inNSUserDefaultsonly the first time and make comparisons the second and subsequent times.