NSTimer requiring me to add it to a runloop

前端 未结 6 1982
盖世英雄少女心
盖世英雄少女心 2020-12-28 16:27

I am wondering if someone can explain why dispatching back to the main queue and creating a repeating NSTimer I am having to add it to RUN LOOP for it too fire?

6条回答
  •  清歌不尽
    2020-12-28 16:40

    Adding the timer to the runloop didn't work in my case. I had to create the timer on the main thread. I was doing this thread creation in a MultipeerConnectivity delegate.

        dispatch_async(dispatch_get_main_queue(), ^{
            self.timer = [NSTimer scheduledTimerWithTimeInterval:self.interval  invocation: self.invocation repeats:YES];
        });
    

提交回复
热议问题