ios之在子线程中使用定时器

时间:2022-02-17 00:11:26
- (void)viewDidLoad
{
    [NSThread detachNewThreadSelector:@selector(timer) toTarget:self withObject:nil];

}

-(void)timer
{
    [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(getGPRS) userInfo:nil repeats:YES];
    //保持线程为活动状态,才能保证定时器执行
    [[NSRunLoop currentRunLoop] run];
}

-(void)getGPRS
{
    NSLog(@"NSTimer");
}