我ALAssetsLibrary用来枚举我保存的照片中的前 30 张照片。我已经创建了属性,AppDelegate以便可以随时访问ALAssets,因为ALAssetsLibrary实例的生命周期与ALAssets生命周期相关。这是我的代码:
if(!_savedAssets) _savedAssets = [[NSMutableArray alloc] init];
else [_savedAssets removeAllObjects];
if(appDelegate.library)
{
[appDelegate.library release];
[appDelegate setLibrary:nil];
}
appDelegate.library = [ALAssetsLibrary new];
__block int count = 0;
[appDelegate.library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
NSLog(@"%d",group.numberOfAssets);
if(count>30) *stop = YES;
[group enumerateAssetsWithOptions:NSEnumerationReverse usingBlock:^(ALAsset *result, NSUInteger index, BOOL *needToStop) {
NSLog(@"%d", index);
if(count<30 && result)
{
UIImage *image = [UIImage imageWithCGImage:result.thumbnail];
[_savedAssets addObject:result];
[self performSelectorOnMainThread:@selector(imageManipulation:) withObject:image waitUntilDone:NO];
count++;
}
else
*needToStop = YES;
}];
} failureBlock:^(NSError *error) {
NSLog(@"%@",error.description);
}];
如您所见,我将前 30 个添加ALAssets到 myNSMutableArray中,以访问缩略图或全尺寸图像。在我的应用程序制作照片后,我将这张照片保存到相机胶卷并尝试ALAssets使用与第一次加载它们时相同的代码重新加载我的照片。在重新加载之前,我从 中删除所有对象NSMutableArray,并重新初始化ALAssetsLibrary. 但这无济于事。每次我都一样ALAssets。我ALAssets只有在重新加载应用程序后才能获得新的。如何在ALAssets不重新加载应用程序的情况下重新加载?