ios-get all the photos inside the system album

Source: Internet
Author: User

#import <AssetsLibrary/AssetsLibrary.h>

-(void) getimgs{

Dispatch_async (Dispatch_get_main_queue (), ^{

NSAutoreleasePool *pool = [[Nsautoreleasepoolalloc] init];

Alassetslibraryaccessfailureblock Failureblock = ^ (Nserror *myerror) {

NSLog (@ "album Access failed =%@", [myerrorlocalizeddescription]);

if ([Myerror.localizeddescription rangeofstring:@ "Global denied access"].location!=nsnotfound) {

NSLog (@ "Unable to access the album.) set the location services as set to open.");

}else{

NSLog (@ "album Access failed.");

}

};

Alassetsgroupenumerationresultsblock groupenumeration = ^ (Alasset *result,nsuinteger Index, BOOL *stop) {

if (result!=null) {

if ([[result Valueforproperty:alassetpropertytype]isequaltostring:alassettypephoto]) {

NSString *urlstr=[nsstring stringwithformat:@ "%@", result.defaultrepresentation.url];//picture URL

Large image of/*result.defaultrepresentation.fullscreenimage//

Thumbnail image of Result.thumbnail//Picture

Nsrange range1=[urlstr rangeofstring:@ "id="];

NSString *resultname=[urlstr substringfromindex:range1.location+3];

Resultname=[resultname stringbyreplacingoccurrencesofstring:@ "&ext=" withstring:@ "."];/ /Format Demo:123456.png

*/

[Self._dataarray ADDOBJECT:URLSTR];

}

}

};

Alassetslibrarygroupsenumerationresultsblock

Librarygroupsenumeration = ^ (alassetsgroup* group,bool* stop) {

if (group = = nil)

{

}

if (Group!=nil) {

NSString *g=[nsstring stringwithformat:@ "%@", group];//gets the group of albums

NSLog (@ "gg:%@", g);//Gg:alassetsgroup-name:camera roll, type:saved Photos, Assets count:71

NSString *g1=[g substringfromindex:16];

Nsarray *arr=[nsarray arraywitharray:[g1componentsseparatedbystring:@ ","]];

NSString *g2=[[arr Objectatindex:0]substringfromindex:5];

if ([G2 isequaltostring:@ "Camera Roll"]) {

[Email protected] "camera roll";

}

NSString the name of the *groupname=g2;//group

[Groupenumerateassetsusingblock:groupenumeration];

}

};

alassetslibrary* Library = [[Alassetslibraryalloc] init];

[Libraryenumerategroupswithtypes:alassetsgroupall

Usingblock:librarygroupsenumeration

Failureblock:failureblock];

[Library release];

[Pool release];

});

}

------------------------reverse the image based on the URL of the image---

Alassetslibrary *assetlibrary=[[alassetslibraryalloc] init];

Nsurl *url=[nsurlurlwithstring:urlstr];

[Assetlibrary assetforurl:url resultblock:^ (Alasset *asset) {

UIImage *image=[uiimage ImageWithCGImage:asset.thumbnail];

Cellimageview.image=image;

}failureblock:^ (Nserror *error) {

NSLog (@ "error=%@", error);

}

];

---------------------

Ios-get all the photos inside the system album

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.