Appreciate any help fixing a crash (EXC_BAD_ACCESS) in my iOS app. I am seeing this since updating my app to iOS 8, using latest available iOS 8.1.2. The same code worked fine i
I was getting this error because the api I called was throwing a 500 and returning html error page in the tmp >> NSData file I was trying to convert to PNG.
I was presuming a statusCode of 200 and the tmp was png.
You may wish to check the file your trying to open is an image at all before conversion.
You can check bytesize of file is 199641 and put in break point
heres how I tracked down CGImageSource issue when downloading the image
func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didFinishDownloadingTo location: URL){
print("didFinishDownloadingToURL[\(location) countOfBytesReceived:\(downloadTask.countOfBytesReceived)]")
if let httpResponse = downloadTask.response as? HTTPURLResponse{
if httpResponse.statusCode == 200{
//----------------------------------------------------------------------------------------
//200 - start
//----------------------------------------------------------------------------------------
if (downloadTask.countOfBytesReceived == 199641){
//bytesize metioned in
: ImageIO: CGImageReadGetBytesAtOffset : * ERROR * CGImageSource was created with data size: 203207 - current size is only: 199641
}else{
//----------------------------------------------------------------------------------------
//Image OK
//----------------------------------------------------------------------------------------
}
//----------------------------------------------------------------------------------------
//200 - 3nd
//----------------------------------------------------------------------------------------
}
else if httpResponse.statusCode == 500
{
//check the tmp file in location path
}else{
}
}else{
appDelegate.log.error("ERROR downloadTask.response NOT HTTPURLResponse for taskDescription:'\(cacheKeyString)' - 500")
}
}