NStimer 后台运行

2016-09-22  本文已影响0人  Hana酱酱酱

使用NSTimer的时候,每当APP进入后台,或者屏幕休眠后,NSTimer就会暂停。

要在后台NSTimer也运行,代码如下:

[[UIApplicationsharedApplication]beginBackgroundTaskWithExpirationHandler:nil];

NStimer theTimer=[NSTimerscheduledTimerWithTimeInterval:1.0target:selfselector:@selector(timerFireMethod)userInfo:nilrepeats:YES];

[[NSRunLoopcurrentRunLoop]addTimer:theTimerforMode:NSRunLoopCommonModes];

上一篇 下一篇

猜你喜欢

热点阅读