简体   繁体   English

打破照片ALAssetsLibrary的迭代

[英]break iteration of photos ALAssetsLibrary

How do I break through the enumeration going on for ALAssetsLibrary enumerateAssets method with a boolean set. 如何使用布尔集突破ALAssetsLibrary enumerateAssets方法的枚举。 Can I just get out of the loop? 我可以摆脱循环吗?

CODE: 码:

[self.library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
    @try {
        if(group != nil) {
            @autoreleasepool {
                    int newNumberOfPhotos = [group numberOfAssets];
                    if (self.numberOfPhotosInSavedPhotos < newNumberOfPhotos) {
                        //only new photos

                        NSRange range = NSMakeRange(self.numberOfPhotosInSavedPhotos, newNumberOfPhotos-self.numberOfPhotosInSavedPhotos);
                        NSIndexSet *indexSet = [NSIndexSet indexSetWithIndexesInRange:range];
                        [group enumerateAssetsAtIndexes:indexSet options:0 usingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
                            @autoreleasepool {
                               if(someCondition)  {
 //get out of the enumeration block (that is, exit the method) or go to complete block
                                }

                                NSString *assetType = [result valueForProperty:ALAssetPropertyType];
                            }
                        } ];
               }         
            }
        } else {
            //enumeration ended

        }

    }
    @catch (NSException *e) {
        NSLog(@"exception streaming: %@", [e description]);
    }
}failureBlock:^(NSError *error){
    NSLog(@"Error retrieving albums stream: %@", [error description]);
    if (error.code==-3312  || error.code==-3311) {
    }
}];

To stop the assets enumeration, just set *stop = YES in the enumeration block. 要停止资产枚举,只需在枚举块中设置*stop = YES

If you want to stop both the outer and the inner enumeration, use different names for the stop variable and set both to YES : 如果要同时停止外部枚举和内部枚举,请对stop变量使用不同的名称,并将两者都设置为YES

[self.library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *outerStop) {
    ...
    [group enumerateAssetsAtIndexes:indexSet options:0 usingBlock:^(ALAsset *result, NSUInteger index, BOOL *innerStop) {
         if (someCondition) {
             *innerStop = YES;
             *outerStop = YES;
         } else {
             // process asset
         }
     }
 }

Remarks: The @try/@catch block should normally not be necessary if you don't have a programming error inside your loops. 备注:如果循环中没有编程错误,通常不需要@try/@catch块。

Your check for "new photos" looks suspicious, because the number of assets in each group is compared with the same number self.numberOfPhotosInSavedPhotos , perhaps you should check that part again. 您对“新照片”的检查看起来很可疑,因为每组中的资产数量与相同的数字self.numberOfPhotosInSavedPhotos ,也许您应该再次检查该部分。

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

相关问题 Iphone:无法使用AlAssetsLibrary显示照片 - Iphone: unable to show photos using AlAssetsLibrary 尝试使用ALAssetsLibrary检索一组照片 - Trying to retrieve a set of photos using ALAssetsLibrary ALAssetsLibrary访问相机胶卷应用程序时崩溃的所有照片1000 + - ALAssetsLibrary accessing all photos 1000 + from camera roll app crashes 如何使用ELCImagePickerController和ALAssetsLibrary在照片库中选择多个图像? - How to select multiple images in Photos Library using ELCImagePickerController and ALAssetsLibrary? 在iOS5中如何在不请求位置访问的情况下使用ALAssetsLibrary访问照片? - How to get access to photos using ALAssetsLibrary without request location access in iOS5? 我可以从照片中选择要使用的元数据,以在关闭位置服务的情况下使用ALAssetsLibrary吗? - Can I pick which meta data to use from photos to be able to use ALAssetsLibrary with location services off? ALAssetsLibrary ALAssetsLibraryDataUnavailableError - ALAssetsLibrary ALAssetsLibraryDataUnavailableError ALAssetsLibrary ALAssetsLibraryAccessUserDeniedError - ALAssetsLibrary ALAssetsLibraryAccessUserDeniedError 将BOOL *传递给ALAssetsLibrary - Passing BOOL * to ALAssetsLibrary ALAssetsLibrary enumerateGroupsWithTypes不返回任何数据 - ALAssetsLibrary enumerateGroupsWithTypes returns no data
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM