/// 获取图片名称
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)
}
网友评论