开发者

NSTimer getting zombie

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜