April 2020 Update
Thankfully, the author of the library recently updated it to include album removal feature discussed in this answer. You can see their pull request. Or refer to the method invocation removeAssetsInAlbum
in the README
Problem
photo_manager
library is using PHAssetChangeRequest's method deleteAssets(_:). You can see this here. This will delete the actual file rather than just remove it from album (more on this in Explanation section)
Solution
The solution is to use PHAssetCollectionChangeRequest's methods. Depends on your use case:
Moving assets from album to another
Removing assets from an album
Adding assets to an album
Explanation
There's a difference between deleting assets and removing assets. Deleting an asset's file is done via PHAssetChangeRequest which deletes the asset file permanently and its references from albums. But removing an asset is done via PHAssetCollectionChangeRequest which removes the asset's reference (not file) from album/s without deleting the file itself. Check this answer.
What to do? How can this solution be applied?
This section is now obsolete but kept for other use-cases when photo_manager
cannot be used, please refer to the top of this answer if you want to use photo_manager
You have the following options to pick one from that would solve your problem:
- Look for the album methods I explained above in the library
photo_manager
, maybe it's there? EDIT1 I just looked for PHAssetCollectionChangeRequest's methods. Currently not supported/used.
- Add an issue to the library and ask the author to make said changes
- Add them to the library yourself via PR or your own cloned version of the
library
- Use a platform channel of your own and handle it yourself.
Example Change:
Currently photo_manager
uses PHAssetChangeRequest
's method deleteAssets(_:):
[PHAssetChangeRequest deleteAssets:result];
This should change to using PHAssetCollectionChangeRequest
's method removeAssets(_:):
[PHAssetCollectionChangeRequest removeAssets:result];