[aLib enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:assetsGroupEnumerationBlock failureBlock:failureBLock];
此方法枚举每个组,我只想对第一个组枚举,然后再中断它。我的目的是寻求iOS首次弹出的许可。我没有做任何其他工作,我在块中有一些通知,用于通知和触发其他必需的功能。但是多个组枚举会多次触发通知,并且我想停止。
这是我的带有stop参数的枚举块
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];
};
但是通知被调用了两次,我nslog
在控制台中看到了两次。
使用stop
参数:
[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
}];
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句