私は(特に現時点では6.0.1)をiOSの6.xでALAssetsLibraryChangedNotificationと協力してきた、と私は結果は私がしたいのカウンタです取得していますドキュメントから理解していることに基づいて、私のuserinfoで受信することを期待しています。ここでIOS 6.0.1 ALAssetsLibraryChangedNotification、送信されているものを理解しようとしている
は、イベント登録のための私のコードです:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(assetsLibraryDidChange:) name:ALAssetsLibraryChangedNotification object:_library];
テストするために、私は私のフォトライブラリに移動し、いくつかの項目を削除して、いくつかの項目を追加します。ここ
は私のハンドラです。
- (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
}
私の出力:削除した後
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)
、およびアルバムを挿入するには、私はALAssetLibraryDeletedAssetGroupsKeyとALAssetLibraryInsertedAssetGroupsKey、およびALAssetLibraryUpdatedAsset *キーのいずれかで何も両方のデータを受信していることを期待しています。何か案は?この通知を受信するApple's sample codeでも、キーを使用することはなく、特定のキーに関係なくすべてのアセットを再列挙することが通知されます(通知情報を信頼しないようなにおいがあります)。
ありがとうございます。 http://developer.apple.com/library/ios/#documentation/AssetsLibrary/Reference/ALAssetsLibrary_Class/Reference/Reference.html#//apple_ref/doc/constant_group/Notification_Keysを読んで、私は私が得ることができるだろうという読み違えます影響を受けるアセットのURLのリスト我々は唯一の資産のリストを取得するようです彼らは*その関連資産*グループについてのみ通知が特に現時点で以来、私はもともと期待していたよりも便利なこの通知をレンダリング、*、*、および挿入または欠失のために変更しているときであります私は1つのグループとしか扱っていません。 –
うん、ドキュメントによると:「挿入または削除ALAssets含むALAssetGroupsを無効化することによって同定されます。」これは非常に残念です。アセットが追加または削除された場合、グループ全体(たとえばカメラロール)をリロードする必要があるようです。 – akaru