【发布时间】:2016-01-13 18:53:27
【问题描述】:
ALAssetsLibrary 这些天已被弃用,但实际上所有关于 SO 的示例仍在使用它。为了我的目标,我需要知道添加到照片库的视频的 URL,以便我可以将视频分享到 Instagram 应用程序(这是 Instagram 接受视频的唯一方式)。 URL 应该以“assets-library://...”开头
这很简单ALAssetsLibrary:
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library writeVideoAtPathToSavedPhotosAlbum:videoFilePath completionBlock:^(NSURL *assetURL, NSError *error) { // ...
在上面,URL 作为参数传递给完成块。但是iOS 9 兼容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 将无法从我的应用程序的沙箱中读取视频
标签: ios swift alassetslibrary photokit