ios - 获取相册列表的简单示例? [英] ios - Simple example to get list of photo albums?

查看:427
本文介绍了ios - 获取相册列表的简单示例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用这里的引用

到目前为止,我在viewDidLoad中有这个:

So far I have this in my viewDidLoad:

// Get albums
NSMutableArray *groups = [NSMutableArray new];
ALAssetsLibrary *library = [ALAssetsLibrary new];

ALAssetsLibraryGroupsEnumerationResultsBlock listGroupBlock = ^(ALAssetsGroup *group, BOOL *stop) {
    if (group) {
        [groups addObject:group];
    }
};
NSUInteger groupTypes = ALAssetsGroupAlbum;
[library enumerateGroupsWithTypes:groupTypes usingBlock:listGroupBlock failureBlock:nil];

NSLog(@"%@", groups);

但是,组数组中没有添加任何内容。我希望看到来自NSLog的2个项目。

However, nothing is added to the groups array. I am expecting to see 2 items from the NSLog.

推荐答案

看起来响应来自异步响应listGroupBlock,但是你的电话会议结束后,NSLog就会出现。因此,组仍然是空的,并且不会在当前线程中填充。

It looks like the response comes in the async response listGroupBlock, but your NSLog comes right after the call. So groups will still be empty and won't be populated in the current thread yet.

如何在listGroupBlock中添加日志记录?

What about adding the logging in listGroupBlock?

ALAssetsLibraryGroupsEnumerationResultsBlock listGroupBlock = ^(ALAssetsGroup *group, BOOL *stop) {
    if (group) {
        [groups addObject:group];
    }
    NSLog(@"%@", groups);

    // Do any processing you would do here on groups
    [self processGroups:groups];

    // Since this is a background process, you will need to update the UI too for example
    [self.tableView reloadData];
};

这篇关于ios - 获取相册列表的简单示例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆