Skip to content

Instantly share code, notes, and snippets.

@cathandnya
Created January 9, 2014 10:48
Show Gist options
  • Save cathandnya/8332367 to your computer and use it in GitHub Desktop.
Save cathandnya/8332367 to your computer and use it in GitHub Desktop.
+ (void) requestPhotoPermission:(void(^)(BOOL))block {
ALAssetsLibrary* assetsLibrary = [[ALAssetsLibrary alloc] init];
ALAuthorizationStatus authStatus = [ALAssetsLibrary authorizationStatus];
if (authStatus == ALAuthorizationStatusAuthorized) {
block(YES);
} else if (authStatus == ALAuthorizationStatusDenied || authStatus == ALAuthorizationStatusRestricted) {
block(NO);
} else if (authStatus == ALAuthorizationStatusNotDetermined) {
[assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
// Catch the final iteration, ignore the rest
if (group == nil)
dispatch_async(dispatch_get_main_queue(), ^{
block(YES);
});
*stop = YES;
} failureBlock:^(NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
block(NO);
});
}];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment