requestAVAssetForVideo没有显示完成块

时间:2017-01-17 19:10:09

标签: objective-c xcode avfoundation icloud photosframework

我有这个代码来加载PHAsset:

PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
options.networkAccessAllowed = YES;

[[PHImageManager defaultManager] requestAVAssetForVideo:[videos objectAtIndex:index]  options:options resultHandler:^(AVAsset *asset, AVAudioMix *audioMix, NSDictionary *info) {
    selectedAsset = asset;
}];

它与存储在设备上的视频完美配合。但如果代码应从iCloud加载视频,则它不会调用完成块。 你能救我吗?

1 个答案:

答案 0 :(得分:-1)

请尝试其他代码1到3

PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
options.networkAccessAllowed = YES;

//Additional code 1
dispatch_semaphore_t semaphore = dispatch_semaphore_create(1);

[[PHImageManager defaultManager] requestAVAssetForVideo:[videos objectAtIndex:index]  options:options resultHandler:^(AVAsset *asset, AVAudioMix *audioMix, NSDictionary *info) {
    selectedAsset = asset;

//Additional code 2
dispatch_semaphore_signal(semaphore);

}];

//Additional code 3
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);