Ios-Get all photos in the system album, ios-get album photos
# 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 url of the image
/* 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 );
}
];
//---------------------