通过assetURL获取到视频

首先导入头文件

1
#import <Photos/Photos.h>

iOS中assetURL样式:

1
assets-library://asset/asset.mov?id=F2E6E143-4343-4B57-87F9-346936E0EDB3&ext=mov

使用当前的URL过滤到我们想要的数据

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
PHFetchResult *result = [PHAsset fetchAssetsWithALAssetURLs:@[assetUrl] options:nil];
PHAsset * PHAsset = result.firstObject;
/// 包含该视频的基础信息
PHAssetResource * resource = [[PHAssetResource assetResourcesForAsset: PHAsset] firstObject];
NSLog(@"%@",resource);
/*
type:
originalFilename:
*/
PHImageRequestOptions * options = [[PHImageRequestOptions alloc] init];
options.version = PHImageRequestOptionsVersionCurrent;
options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
options.synchronous = YES;
__block NSData *videoData = nil;
[[PHImageManager defaultManager] requestImageDataForAsset: PHAsset
options: options
resultHandler: ^(NSData * imageData, NSString * dataUTI, UIImageOrientation orientation, NSDictionary * info) {
NSLog(@"%@",imageData);
//这里的imageData就是视频数据;
}];