Timur Mustafaev
Timur Mustafaev

Reputation: 4929

ALAssetsLibrary returns same assets after adding new photo to camera roll - objective c

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);
}];

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?

Upvotes: 1

Views: 2314

Answers (1)

holtmann
holtmann

Reputation: 6303

Register an observer for ALAssetsLibraryChangedNotification. When the notification fires, reload the assets.

Upvotes: 3

Related Questions