# Import <assetslibrary/assetslibrary. h>
-(Void) getimgs {
Dispatch_async (dispatch_get_main_queue (), ^ {
NSAID utoreleasepool * Pool = [[NSAID utoreleasepoolalloc]
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. Please go to 'settings-> locate service' and set it 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]; // The image URL
/* Result. defaultrepresentation. fullscreenimage // large image
Result. thumbnail // thumbnail of the image
// Nsange 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 album Group
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"]) {
G2 = @ "camera film ";
}
Nsstring * groupname = G2; // group name
[Groupenumerateassetsusingblock: groupenumeration];
}
};
Alassetslibrary * library = [[alassetslibraryalloc]
Init];
[Libraryenumerategroupswithtypes: alassetsgroupall
Usingblock: librarygroupsenumeration
Failureblock: failureblock];
[Library
Release];
[Pool
Release];
});
}
// ------------------------ Reverse image Extraction Based on the image URL -----
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 );
}
];
//---------------------