Reputation: 5698
I have tried some ways to perform NSURLConnection when lock the screen but none of it works.
I have tried as following:
[self performSelectorInBackground:@selector(startConnection) withObject:nil];
I also tried:
dispatch_queue_t request_queue = dispatch_queue_create("com.app.download", NULL);
dispatch_async(request_queue, ^{
[self startConnection];
});
in startConnection:
- (void)startConnection{
... some URL processing
responseData_ = [[NSMutableData alloc] init];
connection_ =
[[NSURLConnection alloc] initWithRequest:urlRequest delegate:self];
}
The NSURLConnection delegate methods aren't called by this way. What is the real code to make it works? Thanks!
A small update that may help:
It only calls this delegate method:
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
with message:
A server with the specified hostname could not be found.
I am very sure my wi-fi is connected, still not sure why it is called :(
Upvotes: 4
Views: 540
Reputation: 7938
If you lock your screen, your app will be turn into background mode, not background running mode. If you want to download while user locks the screen, you should check this method [UIApplication -beginBackgroundTaskWithExpirationHandler:]
Upvotes: 2