0

This app uses NSTimer for triggering images at a certain timeInterval. This works fine but when you zoom in, problems start to occur, the timeIntervals between the images are not constant any more. I have tried two different codes for my timer and they both do not work.

_timerForImageTrigger = [NSTimer scheduledTimerWithTimeInterval:_timeIntervall target:self selector:@selector(automaticTriggerImage) userInfo:nil repeats:YES];

_timerForImageTrigger = [NSTimer timerWithTimeInterval:_timeIntervall
                                             target:self
                                           selector:@selector(automaticTriggerImage)
                                           userInfo:nil
                                            repeats:YES];
    [[NSRunLoop mainRunLoop] addTimer:_timerForImageTrigger forMode:NSRunLoopCommonModes];

What I have done now is disabled zooming when the camera is in record mode. But this is not a solution I want to stick to. Are there any ideas how to fix this or where the problem could be?

BCI
  • 465
  • 6
  • 19
  • automaticTriggerImage is called at correct interval but camera button is not get triggered? or Even the function also doesn't get called? – jailani Feb 12 '14 at 12:58

1 Answers1

1

NSTimers are not guaranteed to fire exactly on time. I believe because your timer is on the main thread it is delayed by other activity on the main thread such as zooming.

This might be helpful Stack Question

You might what to try running the timer on a background run loop.

N.B if you are updating the UI you have to do this on the main thread.

Also you might want to consider changing the tolerance (iOS 7) NSTimer

Community
  • 1
  • 1
geminiCoder
  • 2,918
  • 2
  • 29
  • 50
  • Thank you for the Link. Instead of using NSTimer I am using CADisplayLink, this made it possible, to keep fairly constant timeintevals during recording, even when zooming or focusing. – BCI Feb 14 '14 at 15:51