Skip to content

Instantly share code, notes, and snippets.

@debuggerman
Created July 2, 2011 17:08
Show Gist options
  • Save debuggerman/1061278 to your computer and use it in GitHub Desktop.
Save debuggerman/1061278 to your computer and use it in GitHub Desktop.
using AssetsLibrary to read saved images album in iOS
void (^assetEnumerator)(ALAsset* result, NSUInteger index, BOOL*);
void (^groupEnumerator)(ALAssetsGroup*, BOOL *);
void (^faliure)(NSError*);
groupEnumerator = ^(ALAssetsGroup *group, BOOL *stop){
[group enumerateAssetsUsingBlock:assetEnumerator];
};
assetEnumerator = ^(ALAsset *result, NSUInteger index, BOOL *stop){
CGImageRef image = [result thumbnail];
UIImageView *iv = [[UIImageView alloc] initWithImage:[UIImage imageWithCGImage:image]];
CGRect frame = [iv frame];
frame.origin.x = x;
frame.origin.y = y;
frame.size.width= 30;
frame.size.height = 30;
[iv setFrame:frame];
x = x + 40;
if (x>320) {
x=0;
y += 40;
}
//add to whatever view you are in
[self.window addSubview:iv];
};
faliure = ^(NSError *error){ NSLog(@"Failed"); };
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos
usingBlock:groupEnumerator
failureBlock:faliure];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment