gag*_*rma 9 objective-c ipad ios nsurlsessiondownloadtask
我正在尝试使用NSURL后台会话下载大量文件 nsurlsessiontask.当应用程序在调试模式下运行时(当设备连接到Xcode时),一切都像魅力一样,当从Xcode上拔下设备(iPad)时不起作用.
我正在使用Xcode 7.3.1和iOS 9.3.5.我已经花了几周时间跟踪这个奇怪的行为,但没有任何突破.可能是我遗漏了一些实现后台下载的东西.最近将Xcode升级到8.1.2,将iOS升级到10.2.1,假设升级可能会解决问题,但事实并非如此.
查看我的工作代码,
NSURL *url = [NSURL URLWithString:imageURL];
NSURLSessionTask *_imageDownloadTask = [[NSURLSession sharedSession] dataTaskWithURL:url completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if (data) {
//Here you can read your files from data
if (image) {
dispatch_async(dispatch_get_main_queue(), ^{
//Save your files here for cache purpose
@try {
//You can handle onDownloadFinishWithFile: here too using delegate protocol
}
@catch (NSException *exception) {
NSLog(@"%@", exception.reason);
}
@finally {
// Defines a block of related code that is subsequently executed whether an exception is thrown or not.
}
});
}
}
}];
[_imageDownloadTask resume];
Run Code Online (Sandbox Code Playgroud)
[注意:我使用上面的代码来下载图像]。
| 归档时间: |
|
| 查看次数: |
1458 次 |
| 最近记录: |