获取相册以及拍照图片名称

2019-08-20  本文已影响0人  大炮打小鸟
 /// 获取图片名称
        var imageAsset: PHAsset?
        if #available(iOS 11.0, *) {
            imageAsset = info[.phAsset] as? PHAsset
        } else {
            if let assetURL = info[.referenceURL] as? URL {
                imageAsset = PHAsset.fetchAssets(withALAssetURLs: [assetURL], options: nil).firstObject
            }
        }
    
        if let asset = imageAsset {
            let manager = PHImageManager.default()
            let options = PHImageRequestOptions()
            /// 同步请求, 只返回一次
            options.isSynchronous = true
            /// 允许获取iCloud图片
            options.isNetworkAccessAllowed = true
            
            manager.requestImage(for: asset, targetSize: PHImageManagerMaximumSize, contentMode: .default, options: options) { (img, imgInfo) in
                if let imgURL = imgInfo?["PHImageFileURLKey"] as? URL {
                    let imgName = imgURL.lastPathComponent
                    /// 回调图片
                    self.imgHandle?(image, imgName)
                } else {
                    self.imgHandle?(image, nil)
                }
            }
        } else {
            self.imgHandle?(image, nil)
        }
上一篇 下一篇

猜你喜欢

热点阅读