最近老板突发奇想,要求要在系统相册中创建一个自定义相册,用来保存所有从我们App中下载的视频,并且要能满足随时添加删除的功能.
我的内心是崩溃的.......
研究多天以后终于有一点进展 参考了以下两位的博客写的OC内容
http://www.jianshu.com/p/ea0274a33209
http://www.jianshu.com/p/ddd4bd3d6136
// 获取所有用户自定义的相册
let userCollections : PHFetchResult = PHCollectionList.fetchTopLevelUserCollectionsWithOptions(nil)
// 获取相册名称
for index : Int in 0..<userCollections.count {
let collection = userCollections.objectAtIndex(index) as! PHAssetCollection
if collection.localizedTitle == "UserName" {
// 获取相册信息
let assetsResult : PHFetchResult = PHAsset.fetchAssetsWithMediaType(.Video, options: nil)
let option : PHVideoRequestOptions = PHVideoRequestOptions.init()
option.deliveryMode = .Automatic
for index : Int in 0..<assetsResult.count {
let a : PHAsset = assetsResult.objectAtIndex(index) as! PHAsset
PHImageManager.defaultManager().requestAVAssetForVideo(a, options: option, resultHandler: { (asset, audioMix, info) in
let a = (asset! as! AVURLAsset)
print(a.URL.relativePath)
// print(audioMix)
print(info)
})
}
}
}
网友评论