我已经使用PHAsset原理来获取图像和视频,但是仅显示图像。我也尝试将其更改为NSPredicate,它崩溃了。所以,请问有人可以帮我解决这个问题吗?
私人功能fetchPhotos(){ 让allPhotos = PHAsset.fetchAssets(with:.image,options:assetFetchOptions())
collectionView?.refreshControl?.beginRefreshing()
DispatchQueue.global().async {
allPhotos.enumerateObjects { (asset, count, stop) in
let imageManager = PHImageManager.default()
let targetSize = CGSize(width: 200, height: 200)
let options = PHImageRequestOptions()
options.isSynchronous = true
imageManager.requestImage(for: asset, targetSize: targetSize, contentMode: .aspectFit, options: options, resultHandler: { (image, info) in
if let image = image {
self.images.append(image)
self.assets.append(asset)
if self.selectedImage == nil {
self.selectedImage = image
}
}
if count == allPhotos.count - 1 {
DispatchQueue.main.async {
self.collectionView?.reloadData()
self.collectionView?.refreshControl?.endRefreshing()
}
}
})
}
}
}