我正在研究 PHPhotoLibrary,我在其中创建相册并将图像保存到其中。但是,保存到相册的图像也会出现在“相机胶卷”和“我的照片流”中。
我搜索了很多,没有发现任何实质性的东西。
我写了一个如下的函数,从相机角色和我的照片流中删除照片。
-(void)cleanUpCameraRoll:(NSString *)localID
{
PHFetchResult *newlyCreatedAssetFetchResult = [PHAsset fetchAssetsWithLocalIdentifiers:@[localID] options:nil];
PHAsset *newlyCreatedAsset = [newlyCreatedAssetFetchResult firstObject];
//Get Camera Roll
PHFetchResult *result = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum
subtype:PHAssetCollectionSubtypeSmartAlbumUserLibrary
options:nil];
PHAssetCollection *cameraRollCollection = result.firstObject;
//Get Photo Stream Album - PHAssetCollectionSubtypeAlbumMyPhotoStream
PHFetchResult *result2 = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum
subtype:PHAssetCollectionSubtypeAlbumMyPhotoStream
options:nil];
PHAssetCollection *photoStreamCollection = result2.firstObject;
//*********************************
PHFetchResult *assetsCameraRoll = [PHAsset fetchAssetsInAssetCollection:cameraRollCollection options:nil];
for (PHAsset *asset in assetsCameraRoll) {
if ([asset.localIdentifier isEqualToString:localID]) {
DebugLog(@"Got newly created asset in camera roll");
break;
}
}
PHFetchResult *assetsPhotoStream = [PHAsset fetchAssetsInAssetCollection:photoStreamCollection options:nil];
for (PHAsset *asset in assetsPhotoStream) {
if ([asset.localIdentifier isEqualToString:localID]) {
DebugLog(@"Got newly created asset in photo stream");
break;
}
}
//*********************************
NSError *error;
[[PHPhotoLibrary sharedPhotoLibrary] performChangesAndWait:^{
//Remove from Camera Roll
PHAssetCollectionChangeRequest *changeRequest1 = [PHAssetCollectionChangeRequest changeRequestForAssetCollection:cameraRollCollection assets:newlyCreatedAssetFetchResult];
[changeRequest1 removeAssets:@[newlyCreatedAsset]];
PHAssetCollectionChangeRequest *changeRequest2 = [PHAssetCollectionChangeRequest changeRequestForAssetCollection:photoStreamCollection assets:newlyCreatedAssetFetchResult];
[changeRequest2 removeAssets:@[newlyCreatedAsset]];
} error:&error];
}
这段代码执行得很好,但我仍然在这两个地方看到了图像。
所以,我得出一个结论,相册只是照片的逻辑分组,一切都在相机角色和/或我的照片流中。是这样吗?
如果是的话,有没有办法(至少)让它隐藏在相机胶卷/照片流中?我想让照片仅在我的自定义相册中可见。