【发布时间】:2012-11-09 09:57:02
【问题描述】:
我正在使用NSURLConnection 从服务器下载内容(我正在开发 iOS 5.0 中的 iPad 应用程序)。
我希望即使 iPad 处于待机状态,NSURLConnection 也能继续下载。
有可能吗?
这是我的代码:
-(void)startDownload {
UIDevice* device = [UIDevice currentDevice];
BOOL backgroundSupported = NO;
if ([device respondsToSelector:@selector(isMultitaskingSupported)])
backgroundSupported = device.multitaskingSupported;
NSLog(@"\n\nbackgroundSupported= %d\n\n",backgroundSupported);
dispatch_async(dispatch_get_main_queue(), ^ {
NSURLRequest *req = [[NSURLRequest alloc] initWithURL:imageURL];
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:req delegate:self startImmediately:NO];
[conn scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
[conn start];
if (conn) {
NSMutableData *data = [[NSMutableData alloc] init];
self.receivedData = data;
}
else { ... }
}) ;
}
谢谢!
【问题讨论】:
标签: ios download nsurlconnection standby dispatch-async