- Automatically cancel the timer when the timer holder dealloc
- Automatically cancel all timer when app did enter background. Resume them manually if necessarily.
- Also, Cancel the timer manually if required.
The protocol id has four instance methods as follows:
[resume] : start or resume a timer
[suspend]: suspend the timer
[cancel] : stop the timer
[isRunning]
- Normal timers
[RTTimerManager timerWithInterval:repeated:queue:block:] execute the callback in a specified queue
[RTTimerManager timerWithInterval:repeated:block:] execute the callback in main thread
- Countdown timer
[RTTimerManager countdownTimerWithIdentifier:duration:interval:block]
- Display Link
[RTTimerManager displayLinkWithFrameInterval:block]
/**
Get the timer
*/
__weak typeof(self) werakself = self;
id<RTTimer> timer = [RTTimerManager timerWithInterval:0.1f repeated:YES block:^{
__strong typeof(weakself) this = weakself;
//Do your work in the block using this instead of self if necessarily.
}];
/**
Hold it
*/
self.timer = timer;
/**
Resume
*/
[self.timer resume];
/**
Cancel
*/
[self.timer cancel]; //awake it again by `[self.timer resume]`;
/**
OR
*/
self.timer = nil; //cancel forever
Don't let block retain a strong reference to self