ALAssetsLibrary
這些日子已被棄用,但幾乎所有的例子都在使用它。對於我的目標,我需要知道添加到照片庫的視頻的URL,以便我可以將視頻分享到Instagram應用(這是Instagram接受視頻的唯一方式)。該URL或許應該開始「資產庫:// ...」獲取新創建的資產的URL,iOS 9風格
這是ALAssetsLibrary
簡單:
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library writeVideoAtPathToSavedPhotosAlbum:videoFilePath completionBlock:^(NSURL *assetURL, NSError *error) { // ...
上面,URL作爲參數來完成塊傳遞。但是iOS9兼容方式PHPhotoLibrary
類和performChanges
方法呢?
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?
}
})
爲什麼你不只是在本地保存你的視頻分享之前? –
@LeoDabus視頻共享的方式,Instagram無法從我的應用程序的沙箱中讀取視頻 –