I'm taking image from url my app is crashing on
if let pngImageData = UIImageJPEGRepresentation(img!, 0.25). Crashing only for iPad Air 2 with iOS 10.2.1. Perfectly working for iOS 9.3.5 on iPad 3rd generation, iOS 9.3.5 on iPad 2, iOS 10.2.1 on iPhone 6s, iOS 10.2.1 on iPhone 5s.
Asked
Active
Viewed 71 times
-1
Trup
- 633
- 5
- 17
-
show the crash report – Anbu.Karthik Mar 04 '17 at 08:31
-
Remove **!** from img – Mar 04 '17 at 09:01
-
Possible duplicate of [What does "fatal error: unexpectedly found nil while unwrapping an Optional value" mean?](http://stackoverflow.com/questions/32170456/what-does-fatal-error-unexpectedly-found-nil-while-unwrapping-an-optional-valu) – Hamish Mar 04 '17 at 09:42
1 Answers
1
From the information you provided the only thing that could cause this crash is the img property equals nil.
Please try this:
if let img = img, let pngImageData = UIImageJPEGRepresentation(img, 0.25) { ... }
orxelm
- 1,114
- 14
- 17