NSTimer does not fire in next date time

I need to fire timer on the basis of the time selected in the date picker. Now if the selected time is greater than my current time then the NSTimeInterval returns positive value and the timer fired correctly.

My problem is when I select the time which is less than the current time then the NSTimeInterval returns negative value.

So Now what I does is :- add seconds so that it gets fired next day by 24*60*60.

The seconds value is coming correct because when I test this by changing the time into date it returns the next date with the selected time.

I use these seconds value in setting my timer.

Here is my code :

NSTimeInterval value=[[self.pickerView date] timeIntervalSinceDate:[NSDate date]];

        value=value+24*60*60;
        NSLog(@"value =%f",value);


        NSDate *d1 = [NSDate dateWithTimeIntervalSinceNow:value];
        NSLog(@"%@",d1);
        NSDateFormatter *format=[[NSDateFormatter alloc]init];
        [format setDateFormat:@"dd/MM/yyyy hh:mm:ss a"];
        NSString *str=[format stringFromDate:d1];
        NSLog(@"str=%@",str);
        [format release];
        NSTimer *t = [[NSTimer alloc] initWithFireDate: d1
                                              interval: 1
                                                target: app
                                              selector:@selector(fireWakeUpTimerMethod:)
                                              userInfo:dict repeats:NO];
      //  app.WakeUPTimer=t;
        NSRunLoop *runner = [NSRunLoop currentRunLoop];
        [runner addTimer:t forMode: NSRunLoopCommonModes];
        [t release];

But the timer is not getting fired.

I tested it like this:- Suppose my device current time is 15 june 11:00 am then I select the 10:00 am time in picker view , since 10:00 am is less than 11:00 am then the time interval returns negative value so in this case I do value=value+(24*60*60); and set my timer with this value .Then I open the settings app and change my device date and time to 16 june 9:58 am and close settings app and open my app.But the method did not fire at 10:00 am.Please tell us if this is the correct way of testing this scenario.or I am doing some mistake in testing instead of coding.

Please help me as I am stuck here.

Thanks in advance!

Answers


I assume you are getting value correct:

 value=value+(24*60*60);

Also check target of NSTimer and its selector


Need Your Help

How to clear stack in masm32 coprocessor (FPU)?

masm32 fpu

Doing some operations in masm32 FPU. But I'm not able to clear the stack of FPU e.g. ST(0)-ST(7) afterwards. Is there any instruction for stack clearing. Can you suggest anything?

Mapbox GL regex in Json

json regex mapbox mapbox-gl mapbox-gl-js

I'm trying to only draw contour lines at every 30m of elevation. In mapbox studio this is pretty easy to do using the regex: