1 ALAssetsLibrary( iOS4.0-iOS9.0苹果已经废弃的框架 )
1.1 An instance of ALAssetsLibrary provides access to the videos and photos that are under the control of the Photos application. <ALAssetsLibrary 是访问照相机下的 照片 与 视频 一个实例,简单理解:提供访问相册的能力;使用以前要先进行受权询问
>app
//建立访问相册的实体. ALAssetsLibrary* library = [[ALAssetsLibrary alloc]init]; ALAssetsGroupType:枚举值. ALAssetsGroupLibrary // The Library group that includes all assets. ALAssetsGroupAlbum // All the albums synced from iTunes or created on the device. ALAssetsGroupEvent // All the events synced from iTunes. ALAssetsGroupFaces // All the faces albums synced from iTunes. ALAssetsGroupSavedPhotos // The Saved Photos album. ALAssetsGroupPhotoStream // The PhotoStream album(照片流). ALAssetsGroupAll //ALAssetsGroupAll //遍历所筛选的内容. [library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) { //group类型包括:相机胶卷(Camera Roll),个人照片流 等等 //group 有可能为nil if (group) { //ALAssetsGroup:组的概念至关于一个 个人照片流 NSLog(@"this is albumAssetGroup:%@",[group valueForProperty:ALAssetsGroupPropertyURL]); NSLog(@"this is albumAssetGroup:%@",[group valueForProperty:ALAssetsGroupPropertyName]); NSLog(@"this is albumAssetGroup:%@",[group valueForProperty:ALAssetsGroupPropertyType]); self.customImageView.image = [UIImage imageWithCGImage:[group posterImage]]; //*stop = YES; } //使用过滤器 //Only one filter is active at a time. Any enumeration currently in flight continues to completion using the previous filter. [group setAssetsFilter:[ALAssetsFilter allVideos]]; if ([group numberOfAssets] <= 0 ){ return ; } //这个方法使用的时候有可能会崩溃,前面添加numberOfAssets 进行资源数量的限定 [group enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndex:0] options:0 usingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) { //result:表示一个具体的资源 An ALAsset object represents a photo or a video managed by the Photo application.; if (result) { id representation = [result defaultRepresentation]; NSURL * url = [representation url]; AVAsset* asset= [AVAsset assetWithURL:url]; //NSLog(@"this is this is a asset url :%@",url); } }]; } failureBlock:^(NSError *error) { NSLog(@"error:%@",error.localizedDescription); }];