iOS:使用for循环将PHAsset转换为UIImage时出现内存问题

时间:2017-04-25 12:14:57

标签: ios swift

我想将手机的所有图像保存到模型类中,但是将每个循环应用程序的PHAsset转换为UIImage时会崩溃 这是代码:

fun convertPHAssetsToUIImage(){
    PhotoLibrary.imageList = []
    for index in 0..<fetchResult.count {
        self.imgManager.requestImage(for: self.fetchResult.object(at: index) as PHAsset, targetSize: UIScreen.main.bounds.size, contentMode: PHImageContentMode.aspectFill, options: self.requestOptions) { (image, _) in

            if let image = image {
                let imageAsset = self.fetchResult.object(at: index) as PHAsset
                let imageDetail = ImageDetailsModel(image: image, mediaType: imageAsset.mediaType.rawValue, mediaSubtypes: imageAsset.mediaSubtypes.rawValue.hashValue, sourceType: imageAsset.sourceType.rawValue.hashValue, pixelWidth: imageAsset.pixelWidth, pixelHeight: imageAsset.pixelHeight, creationDate: imageAsset.creationDate, modificationDate: imageAsset.modificationDate, location: imageAsset.location, duration: imageAsset.duration, isHidden: imageAsset.isHidden, isFavorite: imageAsset.isFavorite, burstIdentifier: imageAsset.burstIdentifier, burstSelectionTypes: imageAsset.burstSelectionTypes.rawValue.hashValue, representsBurst: imageAsset.representsBurst)
                PhotoLibrary.imageList.append(imageDetail)

            }
        }
      }
    print(PhotoLibrary.imageList.count)
}

使用主线程也得到相同的错误

0 个答案:

没有答案