ios - NSUrlConnection 什么时候锁屏?

标签 ios background nsurlconnection

我已经尝试了一些方法来在锁定屏幕时执行 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/

相关文章:

ios - 未找到自动链接框架领域

ios - 动画饼图填充模式?

javascript - 使用 div 重新创建行为 "background-attachment: fixed"

css - 使用 css 将图像添加到容器背景

ios - NSURLConnection 返回错误的缓存数据

iOS 视频到音频文件的转换

ios - 使用 AFNetworking 进行 SSL 证书验证

iphone - 如何将 ViewController 添加到 UIPageViewController

objective-c - CMAccelerometerData 类与。弃用的 UIAccelerometer 类

css - 标题上的透明框