What happens to an iPhone app when iPhone goes into stand-by mode?

后端 未结 6 801
忘掉有多难
忘掉有多难 2020-12-02 07:21

My app uses NSTimer and it appears that NSTimer doesn\'t fire when the iPhone goes into the stand-by mode (either by pressing the hardware button or by the idle timer).

6条回答
  •  伪装坚强ぢ
    2020-12-02 07:48

    My first advice is do not disable the idle timer, that is just a hack. If you want to keep a timer alive during UI events run the timer on the current run loop using NSCommonModes:

    // create timer and add it to the current run loop using common modes
    
    self.timer = [NSTimer timerWithTimeInterval:.1 target:self selector:@selector(handleTimer) userInfo:nil repeats:YES];
    [[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
    

提交回复
热议问题