gpt4 book ai didi

ios - 在iOS Swift中从设备获取图像的URL路径

转载 作者:行者123 更新时间:2023-12-01 16:13:52 24 4
gpt4 key购买 nike

我正在尝试在实际设备而非模拟器上使用PHImageManager获取图像路径。
我正在使用photoUrl = info!["PHImageFileURLKey"] as? URL来获取网址。

现在,当我在模拟器上运行代码时,我在 info 中获得了9个键/值对。但是,当我在实际设备上运行相同的代码时,我只得到3个键/值对,因此我没有得到photoUrl并且我的应用程序崩溃

这是我一直在尝试实现的代码,


var selectedPhotos : [URL] = []

func pickerViewController(_ pickerViewController: TatsiPickerViewController, didPickAssets assets: [PHAsset])
{

self.selectedPhotos.removeAll()
let imageManager = PHImageManager.default()
let options = PHImageRequestOptions()
options.deliveryMode = .highQualityFormat
options.resizeMode = .exact
options.isSynchronous = true

let count = assets.count
for asset : PHAsset in assets
{
let imageSize = CGSize(width: asset.pixelWidth,
height: asset.pixelHeight)
/* For faster performance, and maybe degraded image */
imageManager.requestImage(for: asset,
targetSize: imageSize,
contentMode: .aspectFill,
options: options,
resultHandler:
{
(image, info) -> Void in
var photoUrl : URL!
photoUrl = info!["PHImageFileURLKey"] as? URL
self.selectedPhotos.append(photoUrl)
})
}
}

最佳答案

使用asset.requestContentEditingInput而不是asset.requestImagebelowURL中检索图像PHAsset:

func pickerViewController(_ pickerViewController: TatsiPickerViewController, didPickAssets assets: [PHAsset]){

let count = assets.count
for asset : PHAsset in assets{
asset.requestContentEditingInput(with: PHContentEditingInputRequestOptions()) { (eidtingInput, info) in
if let input = eidtingInput, let photoUrl = input.fullSizeImageURL {
self.selectedPhotos.append(photoUrl)
}
}
}
}

关于ios - 在iOS Swift中从设备获取图像的URL路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55789552/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com