有时PHAsset.fetchAssets(with: options)
在具有图片和权限时不返回任何内容。
这是偶发事件,可以通过强制退出并重新启动iOS应用程序来解决。
还有其他人遇到此问题吗?我是否错过了一些重要的内容,例如“有时候您不会因为X而找回图片?”
这是我的代码:
func load() {
ProgressIndicatorView.show(onView: self.view)
PhotosPermissions.tryGetPhotosPermission(
didSucceed: { [weak self] in
DispatchQueue.global(qos: .userInitiated).async {
let options = PHFetchOptions()
options.sortDescriptors = [NSSortDescriptor.init(key: "creationDate", ascending: false)]
options.predicate = NSPredicate(format: "mediaType = %d || mediaType = %d", PHAssetMediaType.image.rawValue, PHAssetMediaType.video.rawValue)
options.includeAllBurstAssets = false
let fetchResults = PHAsset.fetchAssets(with: options)
DispatchQueue.main.async {
self?._assets = fetchResults
self?.collectionView.reloadData()
print("Loaded \(fetchResults.count) images.")
ProgressIndicatorView.hide()
}
}
},
didFail: { [weak self] in
ProgressIndicatorView.hide()
self?.performSegue(withIdentifier: "OpenFormSegue", sender: self)
}
)
}
发生错误时,日志行显示为:Loaded 0 images.