1.ALAssetsLibrary instances provide us with the ability to get pictures and videos from the album (Photo app). The iOS8 photos framework replaced the alassetslibrary.
When using alassetslibrary, we need to declare an instance of it.
alassetslibrary* Library = [[Alassetslibrary alloc] init];
2. Iterate to get albumsAlassetsgroup:
-(void) Enumerategroupswithtypes: (alassetsgrouptype) Types usingblock: ( Alassetslibrarygroupsenumerationresultsblock) Enumerationblock Failureblock: ( Alassetslibraryaccessfailureblock) Failureblock
Alassetsgrouptype: Type
- Alassetsgrouplibrary: Album content from itunes (such as its own sunflower photos).
- Alassetsgroupalbum: Photos that the device itself produces or syncs from itunes, but does not include photo streams and photos in the shared stream. (e.g. pictures saved from various software)
- alassetsgroupevent Camera interface event generated album
- alassetsgroupfaces face album (specifically unclear)
- alassetsgroupsavedphotos Camera Roll photos
- alassetsgroupphotostream Photo stream
- alassetsgroupall In addition to alassetsgrouplibrary above content.
Alassetslibrarygroupsenumerationresultsblock
Alassetslibrarygroupsenumerationresultsblock Listgroupblock = ^ (Alassetsgroup *group, BOOL *stop) { Alassetsfilter *onlyphotosfilter = [Alassetsfilter Allphotos]; [Group Setassetsfilter:onlyphotosfilter]; if ([group Numberofassets] > 0) { [self.imagegroup addobject:group]; } else { [Self.tableview performselectoronmainthread: @selector (reloaddata) Withobject:nil Waituntildone:no] ; } };
Above is the block of the iterative alassetsgroup. Each iteration, the correspondingThe alassetsgroup is stored in a mutable array. Some of the attributes in Alassetsgroup indicate the features of this album. For example:
thumbnails of posterimage albums
Number of photos in Numberofassets album
Valueforproperty gets some properties through NSString, with the following properties
NSString*ConstAlassetsgrouppropertyname;NSString*ConstAlassetsgrouppropertytype;NSString*ConstAlassetsgrouppropertypersistentid; (Unique identification ID)NSString*ConstAlassetsgrouppropertyurl; (Unique identifier URL
#import "AssetsViewController.h" #import <AssetsLibrary/AssetsLibrary.h> @interface Assetsviewcontroller () <UITableViewDataSource,UITableViewDelegate> @property (nonatomic, strong) Alassetslibrary *assetslibrary;@ Property (Nonatomic, Strong) UITableView *tableview; @property (nonatomic, strong) Nsmutablearray *imagegroup; @end @impl Ementation assetsviewcontroller-(alassetslibrary *) assetslibrary{if (!_assetslibrary) {_assetsLibrary = [ALA Ssetslibrary alloc] init]; } return _assetslibrary;} -(Nsmutablearray *) imagegroup{if (!_imagegroup) {_imagegroup = [[Nsmutablearray alloc] initwithcapacity:0]; } return _imagegroup;} -(void) viewdidload {[Super viewdidload]; Do any additional setup after loading the view. [Self.imagegroup removeallobjects]; UITableView *tableview = [[UITableView alloc] InitWithFrame:self.view.bounds Style:uitableviewstyleplain]; [Self.view Addsubview:tableview]; Tableview.delegate = self; Tableview.datasource = self; Alassetslibrarygroupsenumerationresultsblock Listgroupblock = ^ (Alassetsgroup *group, BOOL *stop) {ALAssetsFilter *onl Yphotosfilter = [Alassetsfilter Allphotos]; [Group Setassetsfilter:onlyphotosfilter]; if ([group Numberofassets] > 0) {[Self.imagegroup addobject:group]; } else {[Self.tableview performselectoronmainthread: @selector (reloaddata) Withobject:nil Waitunt Ildone:no]; } }; Nsuinteger grouptypes = Alassetsgroupall; [Self.assetslibrary enumerategroupswithtypes:grouptypes usingblock:listgroupblock failureBlock:^ (NSError *error) {NSLog (@ "Group not found!\n"); }];} -(void) didreceivememorywarning {[Super didreceivememorywarning]; Dispose of any resources the can be recreated.} -(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) section{return Self.imageGroup.count;} -(UITableViewCell *) TableView: (UItableview *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{static NSString *cellname = @ "name"; UITableViewCell *cell = [TableView dequeuereusablecellwithidentifier:cellname]; if (!cell) {cell = [[UITableViewCell alloc] Initwithstyle:uitableviewcellstylesubtitle reuseidentifier:cellname]; } alassetsgroup *group = [Self.imagegroup objectAtIndex:indexPath.row]; UIImage *postimage = [UIImage imagewithcgimage:[group posterimage]; Cell.imageView.image = Postimage; Cell.textLabel.text = [group valueforproperty:alassetsgrouppropertyname];; Cell.detailTextLabel.text = [@ (group.numberofassets) stringvalue]; return cell;}
iOS album Action Alassetslibrary