Created
January 9, 2014 10:48
-
-
Save cathandnya/8332367 to your computer and use it in GitHub Desktop.
This file contains 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) 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