使用ALAssetsLibrary从iphone相册中读取图像

我正在尝试编写一个方法来读取相册中的资源我使用ALAsset从所有相册中获取所有图像,我的问题是如何自定义此方法以从myAlbum读取图像

/** * This method is used to get all images from myAlbum * folder in device if getAlbumImages is set to 1 * else loads all images from devices library */ -(void)readImages:(int)getAlbumImages { imageArray = [[NSArray alloc] init]; mutableArray =[[NSMutableArray alloc]init]; NSMutableArray* assetURLDictionaries = [[NSMutableArray alloc] init]; library = [[ALAssetsLibrary alloc] init]; if(getFolderImages == 1) { // Load images from Shareaflash folder NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder NSString *documentdataPath = [documentsDirectory stringByAppendingPathComponent:@"myFolder"]; NSLog(@"documentdataPath %@",documentdataPath); } else { // Load all images } void (^assetEnumerator)( ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) { if(result != nil) { if([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypePhoto]) { [assetURLDictionaries addObject:[result valueForProperty:ALAssetPropertyURLs]]; NSURL *url = (NSURL*) [[result defaultRepresentation]url]; [library assetForURL:url resultBlock:^(ALAsset *asset) { [mutableArray addObject:asset]; if ([mutableArray count]==count) { imageArray =[[NSArray alloc] initWithArray:mutableArray]; [self allPhotosCollected:imageArray]; } } failureBlock:^(NSError *error){ NSLog(@"operation was not successfull!"); } ]; } } }; NSMutableArray *assetGroups = [[NSMutableArray alloc] init]; void (^ assetGroupEnumerator) ( ALAssetsGroup *, BOOL *)= ^(ALAssetsGroup *group, BOOL *stop) { if(group != nil) { [group enumerateAssetsUsingBlock:assetEnumerator]; [assetGroups addObject:group]; count=[group numberOfAssets]; } }; assetGroups = [[NSMutableArray alloc] init]; [library enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:assetGroupEnumerator failureBlock:^(NSError *error) { NSLog(@"There is an error"); }]; } 

我怎样才能使用documentdataPath加载资产

当您调用enumerateGroupsWithTypes ,请在块中检查资产组名称( valueForProperty: 。 然后,不要将所有资产组添加到您的assetGroups列表中,而只能添加相应的资产组。