UIImageJPEGRepresentation has been replaced by instance method UIImage.jpegData(compressionQuality:)

后端 未结 3 973
旧巷少年郎
旧巷少年郎 2020-12-08 18:38

I\'ve tried to upload a photo to Firebase but it\'s giving me this error. It was working before Xcode 10. I\'m getting this error:

\'UIImageJPEGRepres

相关标签:
3条回答
  • 2020-12-08 19:16

    Just replace

    guard let imageData = UIImageJPEGRepresentation(image, 0.75) else { return }
    

    with:

    guard let imageData = image.jpegData(compressionQuality: 0.75) else { return }
    
    0 讨论(0)
  • 2020-12-08 19:28

    This error occurred in ios 12 and swift 4.2 version.

    let image = UIImage()
    let imageData = UIImageJPEGRepresentation(image, 1)
    
    to:
    
    let image = UIImage()
    let imageData = image.jpegData(compressionQuality: 0.50)
    

    you want to change like this. Please try this it's working for me.

    0 讨论(0)
  • 2020-12-08 19:32

    The error is telling you that as of iOS 12 the old UIImageJPEGRepresentation function has been replaced with the new jpegData method on UIImage.

    Change:

    let imageData = UIImageJPEGRepresentation(image, 0.75)
    

    to:

    let imageData = image.jpegData(compressionQuality: 0.75)
    

    Similarly, the use of UIImagePNGRepresentation has been replaced with pngData().

    0 讨论(0)
提交回复
热议问题