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,
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)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With