let options = PHImageRequestOptions()
options.isSynchronous = true
options.isNetworkAccessAllowed = true//默认关闭
options.resizeMode = .fast
for i in 0..<assets.count {
let asset = assets[i]
PHImageManager.default().requestImage(for: asset, targetSize: CGSize(width: 750, height: 1920), contentMode: PHImageContentMode.default, options: options, resultHandler: { (image, value) in
})
}
有时图片会返回nil,这是由于苹果手机针对手机空间的有限性 ,提供了iCloud 云同步来解决图片视频等占用空间过大的问题 。所以,我们手机本地只需要存放云端图片的资源地址 ,需要时候的时候再去获取 。就节省了手机本地的存储空间 。但是在获取图片的方法中 ,默认却是关闭网络获取iCloud的图片的功能 。if necessary will download the image from iCloud (client can monitor or cancel using progressHandler). Defaults to NO (see start/stopCachingImagesForAssets)