简体   繁体   English

ALAssetsLibrary enumerateGroupsWithTypes不返回任何数据

[英]ALAssetsLibrary enumerateGroupsWithTypes returns no data

I am using the AssetsLibrary framework to retrieve all asset groups in the iPhone. 我正在使用AssetsLibrary框架来检索iPhone中的所有资产组。 I have some code snippet like this: 我有一些这样的代码片段:

NSMutableArray *groups = [[NSMutableArray alloc] initWithCapacity:5];
void (^groupEnumerator)(ALAssetsGroup*, BOOL*) = ^(ALAssetsGroup *group, BOOL *stop) {
    if(group != nil) {
        NSLog(@"Adding group %@", [group valueForProperty:ALAssetsGroupPropertyName]);
        [groups addObject:group];
    }
};

ALAssetsLibrary* library = [AssetsManager defaultAssetsLibrary];
[library enumerateGroupsWithTypes: ALAssetsGroupSavedPhotos
    usingBlock:groupEnumerator
    failureBlock:^(NSError * err) {NSLog(@"Erorr: %@", [err localizedDescription]);}];

And I found a weird behavior: 我发现了一个奇怪的行为:

1) When I run my app in the iOS simulator (use command + R in Xcode), the groupEnumerator will be executed and group names will be printed in the console 1)当我在iOS模拟器中运行我的应用程序(在Xcode中使用命令+ R)时,将执行groupEnumerator并将组名打印在控制台中

2) I wrote some unit test for my app, when I run the unit test (use command + U in Xcode), which calls the above code snippet as it is called in my app, the groupEnumerator seems not get executed at all and none of the group name will be printed, and the failureBlock doesn't get called too and I don't get any error when running the tests but the group enumeration doesn't work as it does in the app. 2)我为应用程序编写了一些单元测试,当我运行单元测试(在Xcode中使用命令+ U)时,它调用了我的应用程序中调用的上述代码段,groupEnumerator似乎根本没有被执行,并且没有组名称中的将会被打印出来,而且也不会调用failBlock,并且在运行测试时也不会出现任何错误,但是组枚举无法像在应用程序中那样起作用。

I check Apple's documentation, and I know this method (enumerateGroupsWithTypes:usingBlock:failureBlock:) is asynchronous, however, even if I wait for a long time in my unit test, I don't see the groupEnumerator get executed. 我检查了Apple的文档,并且知道此方法(enumerateGroupsWithTypes:usingBlock:failureBlock :)是异步的,但是,即使我在单元测试中等待了很长时间,也看不到groupEnumerator被执行。

I am testing against iOS 5.0 with Xcode 4.2. 我正在使用Xcode 4.2针对iOS 5.0进行测试。

Any help is appreciated. 任何帮助表示赞赏。 Thanks. 谢谢。

Stuck on this problem for several days, couldn't figure out the exact cause of this issue. 在这个问题上坚持了好几天,无法找出导致此问题的确切原因。

And instead of using OCUnit in Xcode 4, I had to switch to use gh-unit, which solves this issue actually. 而且,除了在Xcode 4中使用OCUnit之外,我还不得不切换为使用gh-unit,这实际上解决了这个问题。 It seems related with the way Xcode 4 runs the test target. 似乎与Xcode 4运行测试目标的方式有关。

http://gabriel.github.com/gh-unit http://gabriel.github.com/gh-unit

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ALAssetsLibrary enumerateGroupsWithTypes: - 线程同步 - ALAssetsLibrary enumerateGroupsWithTypes: - Thread synchronization 使用[ALAssetsLibrary enumerateGroupsWithTypes:]时的Cocoa线程同步 - Cocoa thread synchronisation when using [ALAssetsLibrary enumerateGroupsWithTypes:] 是否ALAssetsLibrary的enumerateGroupsWithTypes:usingBlock:failureBlock:iOS 4.3.4中的“已损坏”? - Is ALAssetsLibrary's enumerateGroupsWithTypes:usingBlock:failureBlock: “broken” in iOS 4.3.4? iOS-ALAssetsLibrary使用的缓存数据未更新 - iOS - Cached data used by ALAssetsLibrary is not updated iPhone enumerateGroupsWithTypes整理选择器 - iPhone enumerateGroupsWithTypes finishing selector 将新照片添加到相机胶卷后,ALAssetsLibrary返回相同的资源 - 目标c - ALAssetsLibrary returns same assets after adding new photo to camera roll - objective c ALAssetsLibrary ALAssetsLibraryDataUnavailableError - ALAssetsLibrary ALAssetsLibraryDataUnavailableError ALAssetsLibrary ALAssetsLibraryAccessUserDeniedError - ALAssetsLibrary ALAssetsLibraryAccessUserDeniedError 我可以从照片中选择要使用的元数据,以在关闭位置服务的情况下使用ALAssetsLibrary吗? - Can I pick which meta data to use from photos to be able to use ALAssetsLibrary with location services off? 将BOOL *传递给ALAssetsLibrary - Passing BOOL * to ALAssetsLibrary
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM