4

I'm working on an app that takes pictures automatically during certain events and saves them directly to the photo library. Unfortunately the user might not always be looking at their phone when this is running and the first time a picture is taken it asks for permission to access photos.

Is there a way I can force this request during launch and get it out of the way? Thanks

1 Answer 1

6

Yes. You need to request access to the library.
Simply use this code in AppDelegate's didFinishLaunchingWithOptions

ALAssetsLibraryGroupsEnumerationResultsBlock assetGroupEnumerator =
^(ALAssetsGroup *assetGroup, BOOL *stop) {
    if (assetGroup != nil) {
        // do somthing
     }
};

ALAssetsLibraryAccessFailureBlock assetFailureBlock = ^(NSError *error) {
    LogError(@"Error enumerating photos: %@",[error description]);

};

NSUInteger groupTypes = ALAssetsGroupAll;

[library enumerateGroupsWithTypes:groupTypes usingBlock:assetGroupEnumerator failureBlock:assetFailureBlock];
1
  • Fantastic, I've looked everywhere for this! Oct 11, 2012 at 21:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.