用户开启了iCloud 照片库,选择了“优化 iPhone/iPad 储存空间”获取图片失败
?1.出現(xiàn)問題
通過PHCachingImageManager使用requestImageForAsset:targetSize:contentMode:options:resultHandler:方法獲取圖片
為空;
分析原因是圖片存在iCloud.?如果用戶開啟了 iCloud 照片庫(kù),并且選擇了“優(yōu)化 iPhone/iPad 儲(chǔ)存空間”,或者選擇了“下載并保留原件”但原件還沒有加載好的時(shí)候,PhotoKit 也會(huì)預(yù)先拿到這些非本地圖像的 PHAsset,但是由于本地并沒有原圖,所以就需要設(shè)置請(qǐng)求高清圖的請(qǐng)求,這樣PHotoKit 會(huì)嘗試從 iCloud 下載圖片. 這是通過 PHImageRequestOptions 中的值所影響.?
?2.解決方案,可以應(yīng)用版本沒有問題
? ?PHCachingImageManager *imageManager = [[PHCachingImageManager alloc] init];
? ? PHAsset *asset = assets[0];
? ? //解決關(guān)鍵代碼設(shè)置PHImageRequestOptions來實(shí)現(xiàn)緩存iCloud上的內(nèi)容
? ? PHImageRequestOptions *options = [[PHImageRequestOptions alloc]init];
? ? options.networkAccessAllowed = YES;
? ? [imageManager requestImageForAsset:asset targetSize:PHImageManagerMaximumSize contentMode:PHImageContentModeAspectFill options:options resultHandler:^(UIImage *result, NSDictionary *info) {
? ? ? ??dispatch_async(dispatch_get_main_queue(), ^{
? ? ? ? ? ?//處理獲得的圖片
? ? ? ? });
? ? }];
總結(jié)
以上是生活随笔為你收集整理的用户开启了iCloud 照片库,选择了“优化 iPhone/iPad 储存空间”获取图片失败的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 吐故“钠”新,看钠离子电池如何引导行业新
- 下一篇: 神经网络训练失败原因总结