How to receive ALAssetsLibraryChangedNotification in iOS 4 while in background

你。 提交于 2019-12-11 03:49:59

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!