问题
I would like to register my iOS 4 app as an observer for ALAssetsLibraryChangedNotification and receive notifications when changes happen to the camera roll and photo library. The most obvious scenario is: 1) My app enumerates photo contents using ALAssetsLibrary. 2) Leave my app (goes into background) and launch the camera app. 3) Take a picture. 4) Leave the camera app and return to my app.
I was hoping the ALAssetsLibraryChangedNotification would be delivered when my app returned to the foreground, but this does not seem to be the case. I've tried both the block and selector form of addObserver. How can I receive notifications when photos are added or removed while my app is in the background?
回答1:
I handle this by walking through the ALAssetsLibrary and storing all the asset URLs using [[asset defaultRepresentation] url]
. When my app becomes active I walk through the ALAssetsLibrary again, checking against my stored list. Note however that the URL format changes between iOS 4.x and iOS 5.
来源:https://stackoverflow.com/questions/3981161/how-to-receive-alassetslibrarychangednotification-in-ios-4-while-in-background