-
-
Save ideamonk/2409923 to your computer and use it in GitHub Desktop.
using AssetsLibrary to read saved images album in iOS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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