【发布时间】:2015-02-13 12:06:32
【问题描述】:
在我的应用程序中,我想从特定专辑中获取图像和视频。因此,我使用 ALAssetsLibraryGroupsEnumerationResultsBlock 函数从特定专辑中获取图像和视频。在这里,我将资产值存储在 nsmutablearray 中,我获取该数组值viewdidLoad,但在 viewdidload 中数组值为 null。所以当 ALAssetsLibraryGroupsEnumerationResultsBlock 被触发时。 下面是我的代码帮助我..
- (void)viewDidLoad {
[super viewDidLoad];
if (self.assetLibrary == nil) {
_assetLibrary = [[ALAssetsLibrary alloc] init];
}
if (self.groups == nil) {
_groups = [[NSMutableArray alloc] init];
} else {
[self.groups removeAllObjects];
}
[self loadAssetImages];
}
-(void)loadAssetImages{
NSLog(@"Load asset Image ");
ALAssetsLibraryAccessFailureBlock failureBlock = ^(NSError *error) {
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"ERROR" message:[NSString stringWithFormat:@"No Albums Available"] delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
};
ALAssetsLibraryGroupsEnumerationResultsBlock listGroupBlock = ^(ALAssetsGroup *group, BOOL *stop) {
NSLog(@"Block");
if (group == nil)
{
return;
}
if ([[group valueForProperty:ALAssetsGroupPropertyName] isEqualToString:@"FlipDemo"]) {
[self.groups addObject:group];
[self loadImages];
return ;
}
if (stop) {
return;
}
};
NSLog(@"Block Out");
[self.assetLibrary enumerateGroupsWithTypes:ALAssetsGroupAll
usingBlock: listGroupBlock
failureBlock:failureBlock];
}
-(void)loadImages{
NSLog(@"Load Image000");
ALAssetsGroup *assetGroup;
for (assetGroup in self.groups)
{
for (int i = 0; i<[self.groups count]; i++)
{
[ assetGroup enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop)
{
if (result) {
if ([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypeVideo])
{
[videoOnly addObject:result];
}
else if ([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypePhoto])
{
[imgOnly addObject:result];
// NSLog(@"Photo");
}
}
}
];
}
}
}
【问题讨论】:
标签: ios image video alassetslibrary alasset