I have a Phomemo M02 Mini Bluetooth Thermal Printer that I want to print the below image to from my IOS app:
In my app the above image gets taken from a UIView. I've tried converting that image into data and then sending that data to the printer through bluetooth using the CoreBluetooth Framework, but the printer just printed no image and wouldn't stop unrolling it's paper unless I unpaired my app from the device. With that said, does anyone know how to properly send image data, or just an image, to a Phomemo M02 Mini Bluetooth Thermal Printer for it to print it, and for the printer to actually stop unrolling it's paper after drawing the image? That would really be appreciated. Thanks.
Heres my code:
The code for turning my UIView into an image:
extension UIView {
func captureShot () -> UIImage {
UIGraphicsBeginImageContextWithOptions(self.bounds.size, false, self.layer.contentsScale)
drawHierarchy(in: self.bounds, afterScreenUpdates: true)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return ((image != nil) ? image! : UIImage())
}
}
The code for sending the image data to the printer:
let imageData = printView.captureShot().jpegData(compressionQuality: 100)
if (imageData != nil) {
imageView.image = UIImage(data: imageData!)!
print("image size: \(UIImage(data: imageData!)!.size)")
globalPeripheral.writeValue(imageData!, for: characteristic, type: .withResponse)
}