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];
}
changeCo开发者_开发百科unter has infinite loop.But when i run the code and send the app to back.loop runs only for one time?
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).
精彩评论