3

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.

Harish J
  • 525
  • 1
  • 4
  • 16
  • from internet are you saving? if it is, you can find out from camera roll, using image meta data. – karthikeyan Jan 24 '17 at 12:01
  • Thanks Karthik, for your reply. I am getting image info. But, my question is, whether I can stop showing image in camera roll. – Harish J Jan 25 '17 at 11:05
  • If it is custom camera roll view, you can stop it.There is lot of work i can confirm that, we did similar before like stop showing from some album. – karthikeyan Jan 25 '17 at 11:25

2 Answers2

1

Well, this is not an answer but a confirmation of your conclusion. I started writing this as a comment but the formatting is bad, so adding the answe here. Please don't mind.

There's only one way to add to the Photos gallery. All the asset creation requests save the photo in the camera roll. When you add it to an album, only the URL of the asset is added to a list (grouped under one album). The custom ablum picks all the required images from the camera roll.

You can also notice this in other ways: -> If you delete a photo in the album, the photo remains in the camera roll but if you delete it from camera roll, then it is removed from all custom albums.

-> If you notice how an asset is added to an album, you will notice that it is basically retriving the asset from the camera roll. There are no APIs to direct add it to album

Shravya Boggarapu
  • 572
  • 1
  • 7
  • 23
  • Thanks for the reply, Shravya. Can you please give me a reference in the documentation where it mentions the URL of the asset is mapped against album? Also, repeating my second question... do you know a way to, at least, hide the photo in camera roll? – Harish J Jan 25 '17 at 11:00
  • This is mostly my observations based on the available APIs and different experiments as I mentioned. It is very apparent if you look at the older ALAssetLibrary API. – Shravya Boggarapu Jan 25 '17 at 11:25
  • I don't know of any way to hide photos in the camera roll. If I do come across something, I'll be sure to update this. Although, I do remember there was a bug I noticed in an iPhone 5S where some old photos were hidden unless you turned back the date. So, there might be some way, but not publicized – Shravya Boggarapu Jan 25 '17 at 11:33
  • http://osxdaily.com/2014/10/29/how-hide-photos-iphone-ios/ looks like a good starting point. Hide a photo manually and check what properties were changed. Try to reproduce that with code – Shravya Boggarapu Jan 25 '17 at 11:35
0

It is possible, after a fashion, but you'll need to expand the definition of "custom album". As previously noted, any picture added to a photo album via PhotoLibrary callls also gets added to the camera roll.

You can, however, create a directory in your app's document directory for photos, and save photos there. They will not be saved to the device camera roll. The album will also not show up in the photo app. The "custom album" in this instance is just the directory on disk and you would manipulate it (and it's contents) via NSFileManager.

software evolved
  • 4,314
  • 35
  • 45