gpt4 book ai didi

ios - 当我调用 requestImage 时应用程序崩溃

转载 作者:行者123 更新时间:2023-11-28 06:37:33 25 4
gpt4 key购买 nike

当调用此方法时,我的应用程序因错误 Thread 1: EXC_BAD_INSTRUCTION 而崩溃:

imageManager.requestImage(for: asset!, targetSize: CGSize(width:100,height:100), contentMode: .aspectFit, options: options, resultHandler: {(image,info) -> Void in})

View 中的完整代码已加载:

    override func viewDidLoad() {
super.viewDidLoad()
collectionView.delegate = self;
collectionView.dataSource = self;

let fetchResult = PHAsset.fetchAssets(with: PHAssetMediaType.image, options: nil);
let asset = fetchResult.firstObject;

let options = PHImageRequestOptions()
options.deliveryMode = .fastFormat
options.isSynchronous = true

let imageManager = PHCachingImageManager();
imageManager.requestImage(for: asset!, targetSize: CGSize(width:100,height:100), contentMode: .aspectFit, options: options, resultHandler: {(image,info) -> Void in
print("Got image")
})
}

任何人都知道可能导致错误的原因是什么?我认为这与关闭有关,但我不确定哪里出了问题......

这是我尝试调用的方法语法:

func requestImage(for asset: PHAsset, targetSize: CGSize, contentMode: PHImageContentMode, options: PHImageRequestOptions?, resultHandler: (UIImage?, [NSObject : AnyObject]?) -> Void) -> PHImageRequestID

谢谢!

最佳答案

让@James Zaghini 的回答更上一层楼。

您还需要检查 UIImage 或信息是否为 nil

guard let asset = asset else { return }

let imageManager = PHCachingImageManager();
imageManager.requestImage(for: asset, targetSize: CGSize(width:100,height:100), contentMode: .aspectFit, options: options, resultHandler: {(image,info) -> Void in
if let img = image{
print("Got Image")
}
if let imgInfo = info{
print("Info")
}
})

关于ios - 当我调用 requestImage 时应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38780926/

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