I've written the following code (iOS 6) to try to recover the list of photos from an album (albumName) using ALAssetLibrary. The code compiles and according to the static analyzer I don't have memory leaks or other issues, but the NSLog statement. The code successfuly finds the photo album and if I break inside the loop I can see that the data are being written to the Dictionary. But they are not being emplaced as objects in the Array!
I am sure this is an oversight on my part but I am not able to spot it. Any help appreciated, and maybe the correct answer will help someone else. AlAssets has been difficult for me!
Thanks in advance
TF Redfield
- (NSMutableArray )retrieveImageNames: (NSString)albumName {
ALAssetsLibrary* assetsLibrary = [[ALAssetsLibrary alloc] init]; NSMutableArray* assetGroups = [[NSMutableArray alloc] init];
[assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop)
{
if (group)
{
[group setAssetsFilter:[ALAssetsFilter allPhotos]];
[group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop)
{
if (asset)
{
//compare the names of the albums
if ([albumName compare: [group valueForProperty:ALAssetsGroupPropertyName]]==NSOrderedSame)
{
NSMutableDictionary *workingDictionary = [[NSMutableDictionary alloc] init] ;
[workingDictionary setObject:[asset valueForProperty:ALAssetPropertyType] forKey:@"UIImagePickerControllerMediaType"];
[workingDictionary setObject:[UIImage imageWithCGImage:[[asset defaultRepresentation] fullScreenImage]] forKey:@"UIImagePickerControllerOriginalImage"];
[workingDictionary setObject:[[asset valueForProperty:ALAssetPropertyURLs] valueForKey:[[[asset valueForProperty:ALAssetPropertyURLs] allKeys] objectAtIndex:0]] forKey:@"UIImagePickerControllerReferenceURL"];
[assetGroups addObject:workingDictionary];
//If I place the log here I get data
//NSString * temp = [NSString stringWithFormat:@"%d", [assetGroups count]];
//NSLog(@"%@",temp);
[workingDictionary release];
}
}
}];
}
} failureBlock:^(NSError *error)
{
NSLog(@"error enumerating AssetLibrary groups %@\n", error);
}];
NSString * temp = [NSString stringWithFormat:@"%d", [assetGroups count]];
NSLog(@"%@",temp);
return assetGroups;
[assetsLibrary release];
[assetGroups release];
}