Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete photos added in specific albums but not in others?

I wonder in swift and xcode: how do I delete photos added in specific albums but not in others. For example photos added in camera rolls but not in other albums? I know in principle, apple make it only a reference link of the same photo in camera rolls in other album, so if delete in one, you will delete in all others. But would it be possible to make any way around it? For example copy it as a file copy to new album with different names? Any one have any idea how to work around with it ?

Thank you,

like image 800
user1314404 Avatar asked Mar 10 '18 15:03

user1314404


1 Answers

You can use Photos framework to remove the photo from the specific album. You need to PHAssetCollection object (say album) of that album and PHAsset of the photo (say asset) which belongs to that album.

In order to remove the asset from the particular album, you need to create PHAssetCollectionChangeRequest object (say request) with that album and then delete the asset with the help of request using method removeAssets.

Sample

let album : PHAssetCollection = /*Your album object*/
let asset : PHAsset = /*Your Asset belongs to album*/
PHPhotoLibrary.shared().performChanges({
        guard let request = PHAssetCollectionChangeRequest(for: album) else {
            return
        }
        request.removeAssets([asset] as NSArray)
    }) { (result, error) in
        print("completionBlock",result, error)
    }
like image 111
deoKasuhal Avatar answered Nov 14 '22 05:11

deoKasuhal