I am creating an album in the users photo library, now I want to save a video there. I am saving the video to a file using:
let documentsURL = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0]
let filePath = documentsURL.URLByAppendingPathComponent("video")
Now I want to take the video, and save it to an album. I've found lots on saving to the camera roll, but nothing on saving to an album. Can it be done, and if so, how?
Assuming you have a PHAssetCollection specifying the album, you can use this PHAssetCollection extension:
Remarks:
Method 'isCameraRollAlbum' was defined because it was found that the use of placeholders for the whole photo album doesn't work, and you only need to use
PHAssetChangeRequest.creationRequestForAssetFromVideo
to save a video to the whole photo library.
Using a background thread is not necessary.
Example usage, it is assumed a video named 'Video.mov' is in the Documents directory of the app. This will save it to the 'Camera Roll' album but a PHAssetCollection for any album can be specified:
For example, you can use this extension to obtain the PHAssetCollection for an album with a given name 'title':
Example usage, saving video 'Video.mov' to album named 'My Umbrella':
(Keep in mind that the photos library can have multiple albums by the same name.)