English 中文(简体)
How to receive ALAssetsLibraryChangedNotification in iOS 4 while in background
原标题:

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?

问题回答

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.





相关问题
NSNotificationCenter sender equality criteria

Does NSNotificationCenter use pointer equality or some other criteria (like isEqual: or hash:) to determine whether a notification should be sent to an observer?

Tableview reload data problem iphone sdk

I have a class A which is a subclass of uitableviewcontroller and one more class B which actually displays my tableview with its content is a subclass of A. There s an xml parser which parses my xml ...

NSNotification center may not respond to -object?

I m trying to make simple use of the NSNotification center inside my iPhone application, but I seem to be doing something wrong in this case. I was under the impression that it was possible to ...

iPhone - Launching selectors from a different class

I d like to reload a table view which is in another class called "WriteIt_MobileAppDelegate" from one of my other classes which is called "Properties". I ve tried to do this via the ...

NSNotification vs. Delegate Protocols?

I have an iPhone application which basically is getting information from an API (in XML, but maybe JSON eventually). The result objects are typically displayed in view controllers (tables mainly). ...

热门标签