I am using below code to convert an image to Data so that I can send it to my watch extension using watchSession.updateApplicationContext
.
UIGraphicsBeginImageContextWithOptions(localQrView.subviews[0].bounds.size, false, 1.0)
localQrView.subviews[0].layer.render(in: UIGraphicsGetCurrentContext()!)
let viewImage = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
let imageData = viewImage.pngData()
Now the problem is when I execute this code for the first time and see the imageData.count
, it returns only 560 bytes of data. That means, on the watch extension I am not receiving the right data of the image.
From the second time, it gives 14240 bytes which then converts to image normally on the watch extension.
Can anyone see if something is being done wrong here?
PS:
For watch extension, I can't send an Image (UIImage
) directly hence I adopted to the conversion on the app from image to data, and from data to image on the watch extension.