0
我嘗試更新我的現有下載的模式,所以我已經取代我的舊代碼:下載的視頻 - AFHTTPRequestOperation與NSURLSessionDownloadTask
AFHTTPRequestOperation *downloadRequest = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[downloadRequest setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSData *data = [[NSData alloc] initWithData:responseObject];
[data writeToFile:video2Save.localFilePath atomically:YES];
video2Save.downloadComplete = YES;
[YEPersistentModelHelper saveData:_downloadVideos ToDiskWithIdentifier:persistentIdDownloadedVideos];
NSLog(@"file downloading complete : %@", video2Save.localFilePath);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"file downloading error : %@", [error localizedDescription]);
}];
[downloadRequest start];*/
下列要求:
NSURLSessionDownloadTask *downloadTask = [_sessionManager downloadTaskWithRequest:request progress:&progress destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {
NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
return [documentsDirectoryURL URLByAppendingPathComponent:[NSString stringWithFormat:@"%@.mp4",video2Save.videoVersionId]];
} completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) {
NSLog(@"File downloaded to: %@", filePath);
video2Save.localFilePath = [[filePath filePathURL] absoluteString];
video2Save.downloadComplete = YES;
[YEPersistentModelHelper saveData:_downloadVideos ToDiskWithIdentifier:persistentIdDownloadedVideos];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *err = nil;
NSDictionary *att = [fileManager attributesOfItemAtPath:video2Save.localFilePath error:&err];
NSLog(@"NSDictionary: %@", att);
}];
[downloadTask resume];
而且它似乎工作正常。完成塊被執行&該文件存在於跟蹤目標。
問題是,我不再可以播放視頻!我用它拋出這個有用的錯誤的MPMoviePlayerController:
_itemFailedToPlayToEnd: { kind = 1; new = 2; old = 0; }
唯一的區別似乎是該文件的權限。第一個增加了一個「員工」組&每個人都可以閱讀,而第二個只允許訪問「我」。但即使我在取景器中更改它,我也無法播放它...
有沒有人有想法?
哎,我認爲這可能觸發此有用的錯誤;) – niggeulimann