When I use ALAssetsLibrary to get local photos it works fine. But after I delete some photos with the \'Photos\' application my app crashes.
Crash info is:
This seems to be an iOS bug, like you said ALAssetsLibrary returned the wrong number of your photos so you got index out of bounds error. The workaround is to reload your photo again like these:
ALAssetsLibraryGroupsEnumerationResultsBlock
libraryGroupsEnumeration = ^(ALAssetsGroup* group, BOOL* stop)
{
if (group == nil)
{
return;
}
//Force to reload photo as numberOfAssets is broken
NSLog(@"how many picture I have in this group: %d",[group numberOfAssets]);
[group setAssetsFilter:[ALAssetsFilter allPhotos]];//this will cause group to reload
NSLog(@"how many picture I have in this group: %d",[group numberOfAssets]);
if (group!=nil) {
[group enumerateAssetsUsingBlock:groupEnumerAtion];
}
[self updatephotoList];
};