How to ask for access to photo library on startup?

139 views Asked by At

I'm building an app that has the user take photos from their library to do things. I'm using X-code, and I had this code under 'didFinishLaunchingWithOptions' but keep getting an 'undeclared identifier' error. What to do?

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

There are 1 answers

0
Ryan Heitner On

Too late an answer but you need to define library

ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];

or better use a class method if you are going to reuse the library for more queries

+ (ALAssetsLibrary *)defaultAssetsLibrary
{
    static dispatch_once_t pred = 0;
    static ALAssetsLibrary *library = nil;
    dispatch_once(&pred, ^{
        library = [[ALAssetsLibrary alloc] init];
    });
    return library;
}