Need assistance regarding ALAssetsLibrary enumeration

121 views Asked by At
[aLib  enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:assetsGroupEnumerationBlock failureBlock:failureBLock];

This method enumerate every group, I want to enumerate for first group only then I want to break it. My purpose is to ask for permission that iOS pop for first time. I am doing no additional work, I have notifications in blocks that notify and trigger other required functionality. But multiple group enumeration trigger notification multiple times and that I want to stop.

Here is my enumeration block with stop parameter

void(^assetsGroupEnumerationBlock)(ALAssetsGroup*, BOOL*) = ^(ALAssetsGroup *groups, BOOL *stop) {
    *stop = YES;
    NSDictionary *alAuthDict = @{@"alAssetsAuthStatusDictKey" : [NSString stringWithFormat:@"%ld",[self getALAssetAuthorizationStatus]]};
    [[NSNotificationCenter defaultCenter]postNotificationName:@"alAssetsStatusNotificationName" object:nil userInfo:alAuthDict];
};

But notification is getting called two times I see nslog twice in console.

1

There are 1 answers

5
rmaddy On BEST ANSWER

Use the stop parameter:

[lib enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
    *stop = YES;
    if (group) {
        NSDictionary *alAuthDict = @{@"alAssetsAuthStatusDictKey" : [NSString stringWithFormat:@"%ld",[self getALAssetAuthorizationStatus]]};
        [[NSNotificationCenter defaultCenter]postNotificationName:@"alAssetsStatusNotificationName" object:nil userInfo:alAuthDict];
    }
} failureBlock:^(NSError *error) {
    // denied
}];