I seem to be having caching issues with the ALAssetLibrary when testing my app on the iPhone.
Steps used to produce this issue
- Take a photo using the iPhone camera
- Access the Camera Roll using ALAssetsLibrary (through ELCImagePicker)
The problem is that when ELCImagePicker displays the list of albums, the thumbnail of the photo taken in step 1 is displayed for the Camera Roll album (which is correct), but when I go into the Camera Roll album, that photo is not there. An error like this is also displayed in the console log:
Cached count is off for 0x2391d0 <x-coredata://D226A7C3-95D5-40B3-BCFB-726E534AB57A/Album/p1> (1357 != 1358) moc=<PLManagedObjectContext: 0x63794c0>
1357 and 1358 appears to be match the photo count before and after I take the photo, and closing the image picker and opening it again doesn’t help. But if I switch to the Photos app, the photo is displayed there. And when I return to my app, the photo is now displayed as well.
I have tried both
UIImageWriteToSavedPhotosAlbum ( UIImage *image, id completionTarget, SEL completionSelector, void *contextInfo );
and ALAssetsLibrary’s
(void)writeImageToSavedPhotosAlbum:(CGImageRef)imageRef orientation:(ALAssetOrientation)orientation completionBlock:(ALAssetsLibraryWriteImageCompletionBlock)completionBlock
but neither works. Any help is greatly appreciated. Thanks!
You can listen for
ALAssetsLibraryChangedNotificationnotification.In
reloadAlubmGroupsload your album groups from assets library to get updated objects.Apple Documentation: