How to get gallery images in iOS?

后端 未结 2 2064
北荒
北荒 2021-01-15 03:22

I have the task to implement something similar to UIImagePickerController for displaying and selecting images. The problem is to get the list of images on t

2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-15 04:16

    See ALAssetsLibrary class.

    An instance of ALAssetsLibrary provides access to the videos and photos that are under the control of the Photos application.

    Code might be something like this

    void (^assetEnumerator)(struct ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) {
        if(result != NULL) {
            NSLog(@"See Asset: %@", result);
        }
        };
    
        void (^assetGroupEnumerator)(struct ALAssetsGroup *, BOOL *) =  ^(ALAssetsGroup *group, BOOL *stop) {
        if(group != nil) {
                [group enumerateAssetsUsingBlock:assetEnumerator];
        }
        };
    
        library = [[ALAssetsLibrary alloc] init];
        [library enumerateGroupsWithTypes:ALAssetsGroupAlbum
                           usingBlock:assetGroupEnumerator
                         failureBlock: ^(NSError *error) {
                             NSLog(@"Failure");
                         }];
    

提交回复
热议问题