IOS - Print image to Phomemo M02 Mini Bluetooth Thermal Printer using CoreBluetooth in Swift 5

0 votes

I have a Phomemo M02 Mini Bluetooth Thermal Printer that I want to print the below image to from my IOS app:

enter image description here

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)
}

Sep 22, 2022 in Others by gaurav
• 23,260 points
788 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Others

0 votes
0 answers

I Want To Print 1 to 100 Numbers Using Arrays In Javascript Only

Please bear with me as I am ...READ MORE

Aug 18, 2022 in Others by krishna
• 2,820 points
1,050 views
0 votes
1 answer

How to show caller image on iOS native ui call by using callkit framework?

Apple's CallKit is a framework introduced with iOS ...READ MORE

answered Nov 4, 2022 in Others by gaurav
• 23,260 points
1,363 views
0 votes
1 answer

How to print an Excel Sheet using VBA with Nitro PDF Creator in Excel 2016

you can use the built-in excel facilities ...READ MORE

answered Sep 24, 2022 in Others by narikkadan
• 63,600 points
1,352 views
0 votes
0 answers

Sharing a story to Instagram with a background image and a sticker - IOS Swift

I'm trying to share a story with ...READ MORE

Sep 23, 2022 in Others by gaurav
• 23,260 points
769 views
0 votes
0 answers

How to show caller image on iOS native ui call by using callkit framework?

In my iOS app, I am using ...READ MORE

Sep 23, 2022 in Others by gaurav
• 23,260 points
480 views
0 votes
0 answers

How to build a font generator in iOS Swift and allowing pasting to clipboard

I'm now building a listview to display ...READ MORE

Sep 23, 2022 in Others by gaurav
• 23,260 points
555 views
0 votes
1 answer

How do I create folder under an Amazon S3 bucket through PHP API?

Of Course, it is possible to create ...READ MORE

answered Apr 24, 2018 in AWS by anonymous
11,409 views
0 votes
1 answer

Detecting BLE beacons that are not ibeacons on IOS

You'll have to understand that CoreLocation is ...READ MORE

answered Aug 1, 2018 in IoT (Internet of Things) by nirvana
• 3,130 points
881 views
0 votes
1 answer

How can I print variable and string on same line in Python?

Use , to separate strings and variables while printing: print ...READ MORE

answered Sep 17, 2018 in Python by Priyaj
• 58,020 points
3,517 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP