问题描述
我有文件路径
file:///var/mobile/Media/DCIM/100APPLE/IMG_0197.mov
但是当我尝试这段代码时 -
NSError *错误;
NSData * data = [NSData dataWithContentsOfFile:assetUrl.relativePath options:NSDataReadingMappedAlways error:& error];
我什么都没有,只是错误:
文件存在,但我不能读取它。
但同时AVPlayer播放视频文件。
我试过
pre $ PHCetchResult * fetchResult = [PHAsset fetchAssetsWithALAssetURLs:@ [assetUrl] options:nil];
但是我没有得到任何结果。
AVPlayer
)具有例外授权,可以访问这些URL。 要访问
PHAsset
对象的数据,请查看 PHImageManager
的以下方法: 对于图片: requestImageDataForAsset
$ c> requestExportSessionForVideo
I have file at path
file:///var/mobile/Media/DCIM/100APPLE/IMG_0197.mov
But when I try this code-
NSError *error;
NSData *data = [NSData dataWithContentsOfFile:assetUrl.relativePath options:NSDataReadingMappedAlways error:&error];
I got nothing but error:
File exists but I can't read it.
But at the same time AVPlayer normally plays video file.
I tried
PHFetchResult *fetchResult = [PHAsset fetchAssetsWithALAssetURLs:@[assetUrl] options:nil];
But I did not get any result.
You can't access the NSURL
directly as the files are outside of the sandbox of your app. Some frameworks (like AVPlayer
) have exception entitlements and can access the URLs.To access the data of PHAsset
objects take a look at the following methods of PHImageManager
:
For images: requestImageDataForAsset
For videos: requestExportSessionForVideo
这篇关于如何使用PHAsset从文件获取NSData的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!