问题描述
我正在使用 ALAssetsLibrary
来枚举我保存的照片中的前30张照片。我已经在 AppDelegate
中创建了属性,以便在我想要的时候每次都能访问 ALAssets
,因为<$ c $的生命周期c> ALAssetsLibrary 实例与 ALAssets
生命周期相关联。
这是我的代码:
I'm using ALAssetsLibrary
to enumerate first 30 photos in my Saved photos. I've created property in AppDelegate
to have access to ALAssets
everytime when I want, because lifetime of ALAssetsLibrary
instance is tied to ALAssets
lifetime.Here is my code:
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
到我的 NSMutableArray
,可以访问缩略图或全尺寸图像。在我的应用程序制作照片后,我将此照片保存到相机胶卷并尝试使用与我第一次加载它们时相同的代码重新加载我的 ALAssets
。在重新加载之前,我从 NSMutableArray
中删除所有对象,并重新初始化 ALAssetsLibrary
。但这没有帮助。每次我得到相同的 ALAssets
。
我只有在重新加载应用后才能获得新的 ALAssets
。如何在不重新加载应用程序的情况下重新加载 ALAssets
?
As you can see, I'm adding first 30 ALAssets
to my NSMutableArray
, to have access to thumbnail or fullsize image. After my app makes photo, I save this photo to camera roll and try to reload my ALAssets
with same code as when I load them first time. Before reloading, I remove all objects from NSMutableArray
, and reinitializing ALAssetsLibrary
. But this not helps. Each time I get same ALAssets
.I get new ALAssets
only after reloading app. How to reload ALAssets
without reloading app?
推荐答案
注册观察员 ALAssetsLibraryChangedNotification
。
当通知触发时,重新加载资产。
Register an observer for ALAssetsLibraryChangedNotification
.When the notification fires, reload the assets.
这篇关于将新照片添加到相机胶卷后,ALAssetsLibrary会返回相同的资源 - 目标c的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!