iOS上架程序员

swift两种获取相册资源PHAsset的路径的方法(绝对路径)

2018-04-17  本文已影响119人  i_iOS

方法中使用到的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)

})

上一篇下一篇

猜你喜欢

热点阅读