1 //get all pictures of an album2- (void) Reloadimagesfromlibrary3 {4Self.images =[[Nsmutablearray alloc] init];5Dispatch_async (Dispatch_get_main_queue (), ^{6 7 @autoreleasepool {8Alassetslibraryaccessfailureblock Failureblock = ^ (Nserror *myerror) {9NSLog (@"album access failed =%@", [Myerror localizeddescription]);Ten if([Myerror.localizeddescription rangeofstring:@"Global denied access"].location!=nsnotfound) { OneNSLog (@"Unable to access the album. Please set location services as set to ON."); A}Else{ -NSLog (@"album access failed."); - } the }; - -Alassetsgroupenumerationresultsblock groupenumeration = ^ (Alasset *result, Nsuinteger index, BOOL *stop) { - if(result!=NULL) { + - if([[Result Valueforproperty:alassetpropertytype] Isequaltostring:alassettypephoto]) { + ANSString *urlstr=[nsstring stringWithFormat:@"%@", Result.defaultRepresentation.url];//the URL of the picture at [Self.images addobject:urlstr]; - //NSLog (@ "Urlstr is%@", urlstr); - //Result.defaultRepresentation.fullScreenImage//large image of the picture - //Result.thumbnail//thumbnail image of the picture -Nsrange range1=[urlstr rangeofstring:@"id="]; -NSString *resultname=[urlstr substringfromindex:range1.location+3]; inResultname=[resultname stringbyreplacingoccurrencesofstring:@"&ext="Withstring:@"."];//format Demo:123456.png - to } + } - }; the *Alassetslibrarygroupsenumerationresultsblock librarygroupsenumeration = ^ (alassetsgroup* Group, BOOL*stop) { $ Panax Notoginseng if(Group = =Nil) - { the + } A the if(group!=Nil) { +NSString *g=[nsstring stringWithFormat:@"%@", group];//get a group of albums -NSLog (@"gg:%@", g);//Gg:alassetsgroup-name:camera Roll, type:saved Photos, Assets count:71 $ $NSString *g1=[g Substringfromindex: - ] ; -Nsarray *arr=[[Nsarray alloc] init]; -ARR=[G1 componentsseparatedbystring:@","]; theNSString *g2=[[arr Objectatindex:0] Substringfromindex:5]; - if([G2 isequaltostring:@"Camera Roll"]) {WuyiG2=@"Camera Roll"; the } -NSString *groupname=g2;//name of the group Wu - [group Enumerateassetsusingblock:groupenumeration]; About } $ - }; - -alassetslibrary* Library =[[Alassetslibrary alloc] init]; A [Library Enumerategroupswithtypes:alassetsgroupall + usingblock:librarygroupsenumeration the Failureblock:failureblock]; - } $ the }); the}
iOS Traverse pictures in albums