ALAssets use a separated thread to manage enumeration, i have to know when enumeration terminate.
The block prototype for group enumeration is :
typede
I'm using this:
[group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
if (result == nil) {
return;
}
if (index + 1 == group.numberOfAssets) {
//Do what you want. Im using delegate to notify my parent class about finish.
[delegate didGroupEnumerated:group];
}
}];
I found a solution that is documented only in part.
When group enumeration is terminated, ALAssetsLibraryGroupsEnumerationResultsBlock is invoked with group=nil. So you can write something like:
void (^groupsEnumerator)(ALAssetsGroup *,BOOL *) = ^(ALAssetsGroup *group, BOOL *stop){
if (group != nil) {
[group enumerateAssetsUsingBlock:assetsEnumerator];
}else {
NSLog(@"group enumeration terminated");
}
};
The same solution is valid for assets enumeration (this is not documented -.- )
void (^assetsEnumerator)(ALAsset *,NSUInteger,BOOL*) = ^(ALAsset *result, NSUInteger index, BOOL *stop){
if (result !=nil) {
//do something with result asset
}else {
NSLog(@"Assets enumeration terminated");
}
};