IOS バージョンは 9、Xcode 7 で、次のコードが機能しません。ただし、IOS バージョン 8、Xcode 6 で動作します。
以下のコードを使用して、サーバーからファイルをダウンロードしています。
NSURLSessionConfiguration *configuration;
if ([[[UIDevice currentDevice] systemVersion] compare:@"8.0" options:NSNumericSearch] != NSOrderedAscending) {
configuration = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:@"Test"];
} else {
configuration = [NSURLSessionConfiguration backgroundSessionConfiguration:@"Test"];
}
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://hw13.asset.aparat.com/aparat-video/e361693675a47fa4ae758756b40a11653215108-360p__71758.mp4"]];
NSProgress *progress;
NSURLSessionDownloadTask *downloadTask = [manager downloadTaskWithRequest:request progress:&progress destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {
AppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
NSString *fileAddress = [[appDelegate GetDocumentDirectory] stringByAppendingPathComponent:@"Myfile.mp4"];
return [NSURL fileURLWithPath:fileAddress];
} completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) {
if(error != nil){
//ERROR
[[NSFileManager defaultManager] removeItemAtPath:[filePath absoluteString]
error:nil];
[progress removeObserver:self forKeyPath:@"fractionCompleted" context:NULL];
[downloadTask cancel];
return ;
}
//SUCCESS
[progress removeObserver:self forKeyPath:@"fractionCompleted" context:NULL];
}];
[downloadTask resume];
[progress addObserver:self
forKeyPath:@"fractionCompleted"
options:NSKeyValueObservingOptionNew
context:NULL];
エラーが発生し続けます:
Error Domain=NSURLErrorDomain Code=-1 "unknown error" UserInfo={NSErrorFailingURLKey=http://hw13.asset.aparat.com/aparat-video/e361693675a47fa4ae758756b40a11653215108-360p__71758.mp4, NSLocalizedDescription=unknown error, NSErrorFailingURLStringKey=http://hw13.asset.aparat.com/aparat-video/e361693675a47fa4ae758756b40a11653215108-360p__71758.mp4}
ここに GetDocuemntsD があります
-(NSString *)GetDocumentDirectory{
self.fileMgr = [NSFileManager defaultManager];
self.homeDir = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
return self.homeDir;
}
*** 画像をドキュメント ディレクトリに保存できますが、ビデオ ファイルをバックグラウンドでダウンロードして進行状況をユーザーに表示したいのですが、失敗し続けます。
そして私のinfo.plistには次のものがあります:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>