- (void)viewDidLoad {
[super viewDidLoad];
//保证timer在后台运行
[[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:nil];
//创建并执行新的线程
NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(newThread) object:nil];
}
//开一个新线程
- (void)newThread
{
@autoreleasepool
{
//在当前Run Loop中添加timer,模式是默认的NSDefaultRunLoopMode
[NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:@selector(timer_callback) userInfo:nil repeats:YES];
//开始执行新线程的Run Loop
[[NSRunLoop currentRunLoop] run];
}
}
//定时器
- (void)timer_callback
{
NSLog(@"根本停不下来");
}
下面上图