ALAssetsLibrary
is deprecated these days but practically all examples on SO are still making use of it. For my objective, I need to know the URL of the video that was added to the Photo Library so I could share a video to the Instagram app (that's the only way in which Instagram accepts videos). The URL should probably start with "assets-library://..."
This is simple with ALAssetsLibrary
:
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library writeVideoAtPathToSavedPhotosAlbum:videoFilePath completionBlock:^(NSURL *assetURL, NSError *error) { // ...
Above, the URL is passed as an argument to the completion block. But what about iOS 9 compatible way with PHPhotoLibrary
class and performChanges
method?
var videoAssetPlaceholder:PHObjectPlaceholder! // property
// ...
let videoURL = NSBundle.mainBundle().URLForResource("Video_.mp4", withExtension: nil)!
let photoLibrary = PHPhotoLibrary.sharedPhotoLibrary()
photoLibrary.performChanges({
let request = PHAssetChangeRequest.creationRequestForAssetFromVideoAtFileURL(videoURL)
self.videoAssetPlaceholder = request?.placeholderForCreatedAsset
},
completionHandler: { success, error in
if success
{
// The URL of the video asset?
}
})
Here's what I've ended up with:
Nice answer and pseudo, thanks Desmond.
Here is an updated answer :
Swift 3
Going further
Although this works perfectly for the moment, would anyone know a "cleaner" way to get this "assets-library" URL, without this "manual" solution ?
I found this interesting thread, but it only gives a "file:///var/..." URL