Framework:AssetsLibrary.framework
The main purpose is to obtain the data of the system album and display the photos in the System album.
1, create a new project;
2. Add assetslibrary.framework to the project.
3. Open the storyboard, drag and drop a collection view (Collection view) component into the controller, then drag and drop an image view to the default cell of Collection view, and modify the image view display photo in the properties panel as aspect Fill. And, in the Properties panel, set the default cell (Collectionviewcell) identifier fill in the cell;
4, the collection View data source rain Agent export (outlet) connected to the controller (on the collection view right-click, connect on the line, or in the controller's code manually set the line)
5. Add a new class to the project, the class name is MyCell, and inherit from Uicollectionviewcell.
6. In the storyboard, point the class of cell CollectionView to MyCell.
7, associate the ImageView with the code (even to MyCell), named ImageView.
8, import in the controller code
#import <AssetsLibrary/AssetsLibrary.h>
#import "MyCell.h"
And let this class conform to
Uicollectionviewdatasource,uicollectionviewdelegate the specification of the Protocol and then declares two variables
{
Alassetslibrary *library;
Nsmutablearray *imagearr;
}
and link the Uicollectionview to the code. Named as Collview;
-(void) Viewdidload {
[Super Viewdidload];
Library = [[Alassetslibrary alloc]init];
Use parameters to remove all stored file photos
[Library Enumerategroupswithtypes:alassetsgroupsavedphotos usingblock:^ (Alassetsgroup *group, BOOL *stop) {
Nsmutablearray *temparray = [[Nsmutablearray alloc]init];
if (group! = nil) {
[Group enumerateassetsusingblock:^ (Alasset *result, Nsuinteger index, BOOL *stop) {
if (result = nil) {
[Temparray Addobject:result];
}
}];
Save Results
Imagearr = [Temparray copy];
NSLog (@ "Take out photos%lu Zhang", (unsigned long) imagearr.count);
[Self.collview Reloaddata];
}
} failureblock:^ (Nserror *error) {
Failed to read photo
}];
}
#pragma markuicollectionviewdatasource uicollectionviewdelegate
-(Nsinteger) Numberofsectionsincollectionview: (Uicollectionview *) collectionview{
return 1;
}
-(Nsinteger) CollectionView: (Uicollectionview *) CollectionView numberofitemsinsection: (NSInteger) section{
return imagearr.count;
}
-(Uicollectionviewcell *) CollectionView: (Uicollectionview *) CollectionView Cellforitematindexpath: (NSIndexPath *) indexpath{
static NSString *identifier = @ "Cell";
MyCell *cell = [CollectionView dequeuereusablecellwithreuseidentifier:identifier Forindexpath:indexpath];
if (cell = = nil) {
cell = [[MyCell alloc]init];
}
Remove data from each photo and convert to uiimage format
Cgimageref img = [[Imagearr objectAtIndex:indexPath.row] thumbnail];
Cell.imageView.image = [UIImage imagewithcgimage:img];
return cell;
}
IOS get System Album data (not a system album)