I'm using PHPhotoLibrary
to save and fetch images for my application's album in iPhone.
When my album has a lot of images (about 5,000 still images), my application download 10 images from network, then save to Camera roll and add to my application's album.
At the same time, the application observe photoLibraryDidChange
callback to know the added images, but it notify only 5 inserted images.
I finish my application by pushing HOME button and check Camera roll and my album in Photo App. There are correctly 5010 images.
Maybe photoLibraryDidChagne
doesn't notify all changes ?
My code is like below.
- (void)photoLibraryDidChange:(PHChange *)changeInstance
{
// dispatch main queue
dispatch_async(dispatch_get_main_queue(), ^{
[self handleChangedLibrary:changeInstance];
});
}
- (void)handleChangedLibrary:(PHChange *)changeInstance
{
PHFetchResultChangeDetails *fetchResultChangeDetails = [changeInstance changeDetailsForFetchResult:_assetsFetchResult];
if (!fetchResultChangeDetails) {
NSLog(@"### No change in fetchResultChangeDetails ###");
return;
}
if (![fetchResultChangeDetails hasIncrementalChanges]) {
[self fetchAllAssets];
return;
}
NSArray *insertedObjects = [fetchResultChangeDetails insertedObjects];
if (insertedObjects) {
for (PHAsset *asset in insertedObjects) {
if (asset.mediaType == PHAssetMediaTypeImage) {
NSLog(@"asset=%@", asset);
[_stillImageAssetArray addObject:asset];
}
}
}
self.assetsFetchResult = [PHAsset fetchAssetsInAssetCollection:_assetCollection options:nil];
}
I checked inserted asset by NSLog and Debugger and it truly updated 5 images.
There is no notification for the other 5 images.