Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to sync iOS application with ALAssetsLibrary when app comes to foreground

My application keeps a cache of ALAssets. The user may put the app into the background and then use the Photos app, or some other means, to delete some photos or videos. When my app is in the background, I do not get the notification from ALAssetsLibrary that data has changed. Does anyone have an optimal approach to syncing my application state with the ALAssetsLibrary state when the application becomes active again?

Upate: It looks like I can use this approach to iterate back over the entire library, but it seems an inefficient way to get the delta of changes.

How to check if an ALAsset still exists using a URL

like image 678
Gene Z. Ragan Avatar asked Apr 15 '12 16:04

Gene Z. Ragan


Video Answer


1 Answers

You should register for ALAssetsLibraryChangedNotification and only reenumerate the Library, when you receive the notification, that the Library has actually changed. You will receive this notification, when you app is in the foreground again. Please note that, there is a bug in iOS 5.X regarding ALAssetsLibraryChangedNotification: http://www.openradar.me/10484334

Cheers,

Hendrik

like image 178
holtmann Avatar answered Sep 28 '22 06:09

holtmann