iOS album Action Alassetslibrary

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.