HeligPfleigh / react-native-thermal-receipt-printer

A RN library for thermal printer
169 stars 103 forks source link

BLUEPrinter.connect Printer does not connect printer through IOs #147

Closed vilsonei closed 1 year ago

vilsonei commented 1 year ago

Ask your Question

I'm developing an app for iOS, I can list the bluetooth printers by the BLEPrinter.getDeviceList method but when I call the BLEPrinter.connectPrinter method I get the error "'connectPrinter: Can't connect to printer 815DC3CD-7B45-E3FC-9C82-BD0B348CDF40'"

Could anyone give me a tip on how to solve this problem on IOs?

vilsonei commented 1 year ago

Sorted out! The problem was in the sequence of calls, to solve it I did the following:

  1. Call BLEPrinter.getDeviceList()
  2. After success call BLEPrinter.connectPrinter

See the code:

BLEPrinter.getDeviceList().then(devices => {
    BLEPrinter.connectPrinter(mySavedMacAddressPrinter).then(printer => {
        // In IOs the timeout was necessary for the print to be successful.
        setTimeout(() => {
             BLEPrinter.printText(txt);
         }, 1000);
     },
     (e) => {
          console.log(e);
     });
});
joypatel04 commented 10 months ago

@vilsonei

I am working on an iOS app and for some reason, I can't retrieve BLEPrinter.getDeviceList()

Did you receive the list of devices at your end?