I have a question about multithreading in xcode. I have searched for numerous web sites but still cannot get my app to work. I want to do a repeated job every 5sec even the Home button is pressed i.e. continue to time in background. The following is my code:
- (void)viewDidLoad {
[super viewDidLoad];
[NSThread detachNewThreadSelector:@selector(test) toTarget:self withObject:nil];
}
In test.m,
-(void)test {
NSAutoreleasePool 开发者_如何学JAVA*pool = [[NSAutoreleasePool alloc] init];
[NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(sayYeah) userInfo:nil repeats:YES];
[pool release];
}
in sayYeah.m,
-(void)sayYeah {
NSLog(@"yeah");
}
What I expect is "yeah" will continue to pop up every 5sec even the home button is pressed. But it didnt, can anyone have an idea how the multithread should be implemented? Thanks!
You can't unless your app fall is the category VOIP, audio playback or location update.
And you can't use timers.
精彩评论