IOS-Get all the pictures on your phone

Source: Internet
Author: User

1 #import<AssetsLibrary/AssetsLibrary.h>3   4   5 /** 6 * ALAssetsLibrary.h on behalf of the library (all videos, photos) 7 ALAssetsGroup.h represents an album in the Library 8 ALAsset.h represents a video or a photo in a photo album 9 ALAssetRepresentation.h represents a description of a resource that can be retrieved into the original image*/  One   A @interfaceViewcontroller () -   -@property (Weak, nonatomic) Iboutlet Uicollectionview *CollectionView; the   -@property (nonatomic,strong) Nsmutablearray *Array; - @end  -   + @implementationviewcontroller{ -   +Alassetslibrary *Library; A   at }  -   -- (void) Viewdidload { -[Super Viewdidload]; -       -     //creating variable arrays, storing resource files  in_array =[Nsmutablearray array]; -       to     //Create a resource library for access to album Resources  +Library =[[Alassetslibrary alloc] init]; -       the     //Traverse all the albums in the Repository, how many albums are there, how many times Usingblock will be called  *[Library Enumerategroupswithtypes:alassetsgroupsavedphotos usingblock:^ (alassetsgroup *group, BOOL *stop) {  $          Panax Notoginseng         //If there is an album, then Traverse  -         if(group) { the               +             //Traverse all the resources in the album (Photos, Videos)  A[Group enumerateassetsusingblock:^ (Alasset *result, Nsuinteger index, BOOL *stop) {  the                  +                /*44 Index of the resource if (index = = 2) {46 47//Stop traverse 48 *stop = YES; +}*/ Wuyi                  the                if(Result) { -                    //storing a resource in an array  Wu[_array Addobject:result]; -                }  About                  $            }];  -         }  -           -         //refresh _collectionview reloaddata;  A[_collectionview Reloaddata]; +           the} failureblock:^ (Nserror *error) {  -           $NSLog (@"Access failed");  the     }];  the       the }  the   - #pragmaMark-uicollectionviewdelegate in   the //Number of rows  the-(Nsinteger) CollectionView: (Uicollectionview *) CollectionView numberofitemsinsection: (nsinteger) Section { About   the   the     return_array.count; the   + }  -   the //Create Uicollectionviewcell Bayi-(Uicollectionviewcell *) CollectionView: (Uicollectionview *) CollectionView Cellforitematindexpath: (NSIndexPath *) Indexpath { the       the     //if the cell is drawn in the storyboard and does not need to be registered, you need to specify an identifier in the cell  -Uicollectionviewcell *cell = [CollectionView dequeuereusablecellwithreuseidentifier:@"Cell"Forindexpath:indexpath];  -       the     //Get Picture View  theUiimageview *imgview = (Uiimageview *) [Cell.contentview Viewwithtag:1];  the       the     //Take out the corresponding resource data  -Alasset *result =_array[indexpath.row]; the       the     //get to thumbnail image  theCgimageref cimg =[result thumbnail];94       the     //Convert to UIImage  theUIImage *img =[UIImage imagewithcgimage:cimg]; the  98     //Show Pictures  AboutImgview.image =img; -     101     /**102 * Get to Original picture 103 alassetrepresentation *presentation = [result defaultrepresentation];104 the CGI Mageref resolutionimg = [Presentation fullresolutionimage];106*/107 108     returncell;109  the }111  the //Cell Size113-(Cgsize) CollectionView: (Uicollectionview *) CollectionView layout: (uicollectionviewlayout *) collectionviewlayout Sizeforitematindexpath: (Nsindexpath *) indexpath{ the  the     returnCgsizemake ( -, -);

IOS-Get all the pictures on your phone

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.