iOS Traverse pictures in albums

Source: Internet
Author: User

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

Related Article

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.