objective-c - requestAVAssetForVideo 不显示完成 block

我有这段代码来加载 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 加载视频,它不会调用完成 block 。 你能帮帮我吗?

最佳答案

请尝试附加代码 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);

https://stackoverflow.com/questions/41705090/

相关文章:

python - 在 Python 中自动换行打印字符串

wordpress - 如何禁用 Wordpress/Woocommerce 中的自动 https

python - 清除 Selenium 作用链

python-3.x - 无法将音频上传到 Telegram 错误请求 : failed to ge

node.js - 如何让 Heroku 运行子文件夹中的 Node 应用程序?

excel - 如何根据时间应用 WorksheetFunction.CountIfs?

c# - 获取收件箱.Net.Mail C#中的所有电子邮件

javascript - 在javascript中将对象作为参数传递的性能

reactjs - 如何在常规 HTML 页面中引用 React 组件

kubernetes - 如何使用 kubernetes 执行 docker diff 命令