저는 iOS 6.x (6.0.1)에서 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 목록 우리가 자산 목록을 얻는 것만 보였고, 삽입 또는 삭제에 대해서는 관련된 자산 * 그룹에 대한 통지 만 받았기 때문에이 통지는 내가 원했던 것보다 덜 유용하게 만들었습니다. 나는 한 그룹 만 다루고있다. –
그래, 문서에 따르면 : "삽입되거나 삭제 된 ALAsset은 포함하는 ALAssetGroups를 무효화하여 식별됩니다." 이는 매우 불행한 일이며 자산이 추가되거나 제거 된 경우 전체 그룹 (예 : 카메라 롤)을 다시로드해야하는 것 같습니다. – akaru