Search code examples
iosalassetslibrarynsrangeexception

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 ?


Solution

  • 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.