0

I need a little bit of help in here, I have a method that saves an UIImage into the my custom images folder, but images saving into the camera roll folder as well which is i don't want.

Please, can anyone suggest me how can i restrict to save into camera roll folder ?

NSString *albumName = @"myApp";
void (^saveBlock)(PHAssetCollection *assetCollection) = ^void(PHAssetCollection *assetCollection) {
    [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{

        PHAssetChangeRequest *assetChangeRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:image];
        PHAssetCollectionChangeRequest *assetCollectionChangeRequest = [PHAssetCollectionChangeRequest changeRequestForAssetCollection:assetCollection];
        [assetCollectionChangeRequest addAssets:@[[assetChangeRequest placeholderForCreatedAsset]]];

    } completionHandler:^(BOOL success, NSError *error) {
        if (!success) {
            NSLog(@"Error creating asset: %@", error);
        }
    }];
};

PHFetchOptions *fetchOptions = [[PHFetchOptions alloc] init];
fetchOptions.predicate = [NSPredicate predicateWithFormat:@"localizedTitle = %@", albumName];
PHFetchResult *fetchResult = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeAny options:fetchOptions];

if (fetchResult.count > 0) {
    saveBlock(fetchResult.firstObject);
} else {
    __block PHObjectPlaceholder *albumPlaceholder;
    [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{

        PHAssetCollectionChangeRequest *changeRequest = [PHAssetCollectionChangeRequest creationRequestForAssetCollectionWithTitle:albumName];
        albumPlaceholder = changeRequest.placeholderForCreatedAssetCollection;

    } completionHandler:^(BOOL success, NSError *error) {
        if (success) {
            PHFetchResult *fetchResult = [PHAssetCollection fetchAssetCollectionsWithLocalIdentifiers:@[albumPlaceholder.localIdentifier] options:nil];
            if (fetchResult.count > 0) {
                saveBlock(fetchResult.firstObject);
            }
        } else {
            NSLog(@"Error creating album: %@", error);
        }
    }];
}
NSLog(@"Count : %lu",(unsigned long)[arrForHereLoImages count]);
mast3rd3mon
  • 8,229
  • 2
  • 22
  • 46
TechValens
  • 437
  • 6
  • 20

1 Answers1

0

Camera Roll contains all the devices pictures. This is by design in iOS. You can't prevent that.
Your image is not saved twice but actually saved in the camera roll and referenced in your custom Album.

Quentin Hayot
  • 7,786
  • 6
  • 45
  • 62