Background Execution
I am doing SMTP related app in my application, to send th开发者_StackOverflowe mail.In IOS 4 background execution exceptions for audio,voip,location.How to use network operation.
There is no explicit exception for network access. You can request extra time to complete a task after your app exits but you can't create a daemon process that continually runs in the background.
Apple provides 600 sec to execute background task you can take help with code
UIApplication *app = [UIApplication sharedApplication];
self.bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
// Start the long-running task
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
while (1) {
NSLog(@"BGTime left: %f", [UIApplication sharedApplication].backgroundTimeRemaining);
[self.viewController performSelector:@selector(invokeCuisineSelector)];
sleep(1);
}
});
精彩评论