swift两种获取相册资源PHAsset的路径的方法(绝对路径)
方法中使用到的phasset就是我们取到的PHAsset对象
方法一:
let options = PHVideoRequestOptions()
options.version = PHVideoRequestOptionsVersion.current
options.deliveryMode = PHVideoRequestOptionsDeliveryMode.automatic
let manager =PHImageManager.default()
manager.requestAVAsset(forVideo: phasset, options: options, resultHandler: { (asset, audioMix, info) in
let strArr = ((info!asNSDictionary).object(forKey:"PHImageFileSandboxExtensionTokenKey")as!NSString).components(separatedBy:";")
let url = strArr.last!
print(url)
})
方法二(比较简洁):
PHCachingImageManager().requestAVAsset(forVideo: phasset as PHAsset, options:nil, resultHandler: { (asset, audioMix, info) in
let strArr = ((info!asNSDictionary).object(forKey:"PHImageFileSandboxExtensionTokenKey")as!NSString).components(separatedBy:";")
let url = strArr.last!
print(url)
})