I am working on PHPhotoLibrary, where I create an album and save image to it. But, the image being saved to the album also appears in the Camera Roll as well as My Photo Stream.
I searched a lot, nothing substantial found.
I wrote a function as below, to remove the photos from camera role and my photo stream.
-(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];
}
This code executes well, but still i see the images at both the places.
So, I am coming to a conclusion, that Albums are just logical groupings of the photos, and everything lies within Camera Role and/or My Photo Stream. Is that so?
If yes, is there any way to (at least) make it hidden in the camera roll/Photo stream? I want to make photos visible only in my custom album.