我已经尝试了一些方法来在锁定屏幕时执行 NSURLConnection,但都没有用。
我试过如下:
[self performSelectorInBackground:@selector(startConnection) withObject:nil];
我也试过:
dispatch_queue_t request_queue = dispatch_queue_create("com.app.download", NULL);
dispatch_async(request_queue, ^{
[self startConnection];
});
在开始连接中:
- (void)startConnection{
... some URL processing
responseData_ = [[NSMutableData alloc] init];
connection_ =
[[NSURLConnection alloc] initWithRequest:urlRequest delegate:self];
}
NSURLConnection 委托(delegate)方法不是通过这种方式调用的。 使其工作的真正代码是什么?谢谢!
可能有帮助的小更新:
它只调用这个委托(delegate)方法:
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
留言:
A server with the specified hostname could not be found.
我非常确定我的 wi-fi 已连接,但仍然不确定为什么叫它 :(
最佳答案
如果您锁定屏幕,您的应用将转为后台模式,不是后台运行模式。 如果你想在用户锁定屏幕时下载,你应该检查这个方法 [UIApplication -beginBackgroundTaskWithExpirationHandler:]
关于ios - NSUrlConnection 什么时候锁屏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14096674/