ALAssetsLibrary’s enumerateGroupsWithTypes:usingBlock:failureBlock: on iOS 4.3.4

I had 20 minutes of panic after installing iOS 4.3.4 on my iPhone 4. In fact, the app which I’m developing has stopped working due to a change in the ALAssetsLibrary api. The call to enumerateGroupsWithTypes:usingBlock:failureBlock:, which I use to retrieve all the media files on the device, did nothing (blocks didn’t get called and no error raised). After a couple of tests:

NSLog(@"is selector available? %@", 
[library respondsToSelector:@selector(enumerateGroupsWithTypes:usingBlock:failureBlock:)] ? @"y" : @"n");
NSLog(@"I'm on the main thread? %@", [NSThread isMainThread] ? @"y" : @"n");

I figured out that the fetching didn’t begins because it was invoked on a background thread (although this did works fine in iOS 4.3.3!).
In fact I’m using an NSOperationQueue with several NSOperations inside and one of them is the one invoking ALAssetsLibrary’s api.
So, to solve the problem I simply created a wrapper to the call using performSelectorOnMainThread:withObject:waitUntilDone:

After a code refactoring and the upgrade to iOS 5, I finally realized that the problem is actually related to how ALAssetsLibrary works. read here!