简体   繁体   中英

NSRangeException using -[ALAssetsGroup enumerateAssetsUsingBlock:]

I am currently using some pretty standard code to enumerate assets in a group. Except now I have a new error

*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSOrderedSet enumerateObjectsAtIndexes:options:usingBlock:]: index 46 beyond bounds [0 .. 45]'

Here is the code that I am using.

 [group enumerateAssetsWithOptions:NSEnumerationReverse usingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
            NSLog(@"Asset %@", result);
            if (result != nil)
            {
                Asset *asset = [provider newAsset];
                asset.date = [result valueForProperty:ALAssetPropertyDate];
                id duration = [result valueForProperty:ALAssetPropertyDuration];
                asset.duration =  [NSDecimalNumber decimalNumberWithString:[NSString stringWithFormat:@"%@", duration]];
                CLLocation *location = [result valueForProperty:ALAssetPropertyLocation];
                asset.location = [location description];
                asset.orientation = [result valueForProperty:ALAssetPropertyOrientation];
                asset.type = [result valueForProperty:ALAssetPropertyType];
                NSDictionary *urls = [result valueForProperty:ALAssetPropertyURLs];
                for (NSString * key in urls) {
                    NSLog(@"Url = %@",[urls objectForKey:key]);
                    asset.url = [NSString stringWithFormat:@"%@", [urls objectForKey:key]];
                }

                [assetGroup addAssetsObject:asset];

                [asset release]; // Corrected based on comments

            }
        }];

The provider object is my custom database provider. But eliminating this code does no good. the top NSLog never gets fired which tells me that the enumeration code is having a problem outside my control. Has anyone else experienced this ?

I'm seeing the same issue. It's a bug on Apple's side.

They execute the enumeration block in a separate thread and crash going out of bounds. What a shame! I cannot find a way to even catch this. App crashes, and there is nothing you can do until their library fixes itself.

Modifying the Camera Roll or sometimes launching iPhoto for iPad fixes the problem, but it will come back. Fortunately, it does not happen too often, but Apple has to react to this.

This bug can be circumvented by setting the filters to photos, then videos, and enumerating for each one in turn, instead of keeping it at the default 'assets'.

I posted details here: ALAssetsLibrary seems to return wrong number of my photos

Something was apparently messed up with my photo library. After clearing out my photos and running the application again, I am no longer getting this issue.

Sure wish I knew what the actual problem was and why the AssetsLibrary tried enumerating past the Bounds.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM