开发者

NSTimer getting zombie

开发者 https://www.devze.com 2023-04-12 15:35 出处:网络
I have created a NSTimer in my application which gets fired after every 1 min interval. my problem is when I put the application in ba开发者_Go百科ckground and after some time say 5 min, i bring that

I have created a NSTimer in my application which gets fired after every 1 min interval. my problem is when I put the application in ba开发者_Go百科ckground and after some time say 5 min, i bring that in foreground, the timer object gets zombied.

any thoughts on this.


Perhaps invalidate the timer when the application enters the background then start it again when the application enters the foreground.

Like so:

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    [myTimer invalidate];
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    myTimer = [NSTimer scheduledTimerWithTimeInterval:60.0 target:self selector:@selector(TimerFunction) userInfo:nil repeats:YES];
}


NSTimer objects are retained when scheduled. Your timer might be invalidated for some reason and by thus, released.

0

精彩评论

暂无评论...
验证码 换一张
取 消