i've been working with ALAssetsLibraryChangedNotification in iOS 6.x (6.0.1 specifically at the moment), and i'm getting results are counter to what i'd expect to recieve in my userinfo, based on what I understand from the documentation.
Here's my code for event registration:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(assetsLibraryDidChange:) name:ALAssetsLibraryChangedNotification object:_library];
to test, i go into my photo library, and delete some items, add some items.
here's my handler.
- (void)assetsLibraryDidChange:(NSNotification *)note
{
NSDictionary* info = [note userInfo];
NSLog(@"assetsLibraryDidChange calling syncPhotoInfoFromAssets, userInfo %@", info);
// If the user information dictionary is nil, reload all assets and asset groups.
if(note.userInfo==nil) {
[self syncPhotoInfoFromAssets];
return;
}
// If the user information dictionary an empty dictionary, there is no need to reload assets and asset groups.
if(note.userInfo.count == 0) {
return;
}
// If the user information dictionary is not empty, reload the effected assets and asset groups. For the keys used, see “Notification Keys.”
NSSet *updatedAssets = [info objectForKey:ALAssetLibraryUpdatedAssetsKey];
NSSet *updatedAssetGroup = [info objectForKey:ALAssetLibraryUpdatedAssetGroupsKey];
NSSet *deletedAssetGroup = [info objectForKey:ALAssetLibraryDeletedAssetGroupsKey];
NSSet *insertedAssetGroup = [info objectForKey:ALAssetLibraryInsertedAssetGroupsKey];
NSLog(@"updated assets:%@", updatedAssets);
NSLog(@"updated asset group:%@", updatedAssetGroup);
NSLog(@"deleted asset group:%@", deletedAssetGroup);
NSLog(@"inserted asset group:%@", insertedAssetGroup);
//further processing here
}
my output:
ALAssetLibraryUpdatedAssetGroupsKey = "{(\n assets-library://group/?id=736B6346-6DA2-4E43-8830-9C263B2D29ED\n)}";
ALAssetLibraryUpdatedAssetsKey = "{(\n assets-library://asset/asset.JPG?id=A695208B-3546-4CCA-B539-B1D132A209B3&ext=JPG\n)}";
}
2013-01-06 22:50:45.738 Olesi[25468:3613] updated assets:{(
assets-library://asset/asset.JPG?id=A695208B-3546-4CCA-B539-B1D132A209B3&ext=JPG
)}
2013-01-06 22:50:45.738 Olesi[25468:3613] updated asset group:{(
assets-library://group/?id=736B6346-6DA2-4E43-8830-9C263B2D29ED
)}
2013-01-06 22:50:45.739 Olesi[25468:3613] deleted asset group:(null)
2013-01-06 22:51:06.658 Olesi[25468:3613] inserted asset group:(null)
After deleting, and inserting an album, i expect to have received data in both the ALAssetLibraryDeletedAssetGroupsKey and ALAssetLibraryInsertedAssetGroupsKey, and nothing in either of ALAssetLibraryUpdatedAsset*Key. Any ideas? I notice that even Apple's sample code that listens to this notification doesn't even make use of the keys, but rather re-enumerates all assets regardless of the specific key (which smells like they don't trust the notification info)