开发者

Background repeated job

开发者 https://www.devze.com 2023-03-23 01:34 出处:网络
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.

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.

0

精彩评论

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