I am writing an application where the user could select several images and ask them to be saved to the library. I use ALAssetLibrary to create a list of all the images in the gallery for the user to choose from. When the user asks for save, I save the images one at a time to saved photos using [library writeImageToSavedPhotosAlbum:metadata:completionBlock:]. So I first save one image and then in the completion block, save another image and so on.
I expect the ALAssetsLibraryChangedNotification to be called as many times as the number of images to be saved. But it is being called twice as many times. Any clues why this might happen? I have checked that I am actually writing the images only once for every selected image. The notifications occur immediately after I save each image. Once I receive all notifications once for every saved image, I reload the library and load the assets again. The notifications then start come again each time I finish reloading the assets.
Is there a way I can get to know if there are more such notifications coming up so that I can choose to perform the actual processing only after the last one?
The best solution that I found to go through this was to remove the observer before performing save operations.
And then subscribe to the notifications again after everything has been saved.