0

I'm using the BSImagePicker Image Picker controller (See here)

The image picker controller returns PHAsset rather than UIImage, so I found out how to convert PHAsset to UIImage using this function:

PHAsset to UIImage

func getAssetThumbnail(asset: PHAsset) -> UIImage {
    let manager = PHImageManager.default()
    let option = PHImageRequestOptions()
    var thumbnail = UIImage()
    option.isSynchronous = true
    manager.requestImage(for: asset, targetSize: CGSize(width: 100, height: 100), contentMode: .aspectFit, options: option, resultHandler: {(result, info)->Void in
        thumbnail = result!
    })
    return thumbnail
}

Issue is that, I want to return the targetSize of PHImageManagerMaximumSize. Althought when this happens, I get an errorrThis application is modifying the autolayout engine from a background thread after the engine was accessed from the main thread. This can lead to engine corruption and weird crashes.

The error doesn't occur when I set targetSize to CGSize(width: 100, height: 100)

Community
  • 1
  • 1
luke
  • 2,743
  • 4
  • 19
  • 43

1 Answers1

1

Just you need to do to avoid your error is to force the application to modify the auto layout on the main thread. You can for example use a dispatcher in the main queue when you set your image. For example:

let image = self.getAssetThumbnail(asset: <YourPHAsset>)

        DispatchQueue.main.async {

            self.imageView.image = image
        }

The error should occur also when you use a targetSize... Strange...

Pierre Perrin
  • 335
  • 3
  • 13