mobile.jugnu
mobile.jugnu

Reputation: 629

how to run NSThread when app goes to background

I need to control the volume of device when app is in background so for this i use following code

 - (void)applicationDidEnterBackground:(UIApplication *)application
 {
back=1;

NSLog(@"Enter in the back");
float v=1.0f;

[NSThread detachNewThreadSelector:@selector(changeCounter) toTarget:self withObject:_viewController];

}

changeCounter has infinite loop.But when i run the code and send the app to back.loop runs only for one time?

Upvotes: 0

Views: 1488

Answers (1)

Joe
Joe

Reputation: 57179

You need to request a background task from the UIApplication using beginBackgroundTaskWithExpirationHandler. There are examples in the Application Programming Guide (See the Completing a Finite-Length Task in the Background section).

Upvotes: 2

Related Questions