ios - NSTimer not reliable when transitioning to background -


i'm using nstimer play audio file every x number of seconds. audio files in sync running process, interval of nstimer shortest can (to knowledge):

self.updatetimer = [nstimer scheduledtimerwithtimeinterval:0.02 target:self selector:@selector(updatetimerfired:) userinfo:nil repeats:yes]; [[nsrunloop mainrunloop] addtimer:self.updatetimer formode:nsrunloopcommonmodes]; 

my problem occurs during transition background state e.g. when user clicks home button. seems latency occurs timer, , "updatetimerfired:" method isn't called reliably during transition. results in audio files playing out of sync, although sync after transition complete. note app incorporates audio background mode.

is there more reliable tool other nstimer ensure latency not occur when transitioning background?

ended replacing nstimer dispatch_source_create:

self.timerqueue = dispatch_queue_create("updatetimerqueue", nil); self.updatetimer = dispatch_source_create(dispatch_source_type_timer, 0, 0, self.timerqueue); dispatch_source_set_timer(self.updatetimer, dispatch_time_now, (1 * nsec_per_sec) / 50, (1 * nsec_per_sec) / 20);  dispatch_source_set_event_handler(self.updatetimer, ^{     [self updatetimerfired]; }); dispatch_resume(self.updatetimer); 

this provides dedicated queue timer perform on, , not interrupted transition background.


Comments