HeligPfleigh / react-native-thermal-receipt-printer

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

iOS: NetPrinter does not work. #31

Open harshmaur opened 3 years ago

harshmaur commented 3 years ago
useEffect(() => {
    NetPrinter.init().then(() => {
      NetPrinter.connectPrinter('192.168.1.105', 9100).then(
        (printer) => console.log(printer),
        (error) => console.warn(error)
      )
    })
  }, [])
  1. When I give a port 9100 it gives me the following error.

    Screenshot 2020-11-22 at 11 31 36 AM
  2. If I remove the port, the it displays success on an IP regardless of whether the printer is there or not and doesnt print the bill.

It works fine on android.

FYI: I am using iOS simulator.

HeligPfleigh commented 3 years ago
  1. The port type should be string
  2. Could you try this to listent the event emitter like code below
import {
  NetPrinterEventEmitter,
  RN_THERMAL_RECEIPT_PRINTER_EVENTS 
} from 'react-native-thermal-receipt-printer';

....
const YourComponent: React.FC = () => {
  ...
  React.useEffect(() => {
    NetPrinterEventEmitter.addListener(RN_THERMAL_RECEIPT_PRINTER_EVENTS.EVENT_NET_PRINTER_SCANNED_SUCCESS, (printers) => console.log(printers))
  }, []);
  ....
}

then connect to printer by the record in that list printers. May be I have a wrong message when resolve connectPrinter function here, it only triggers the connecting => need to wait until the .a lib send a success notification

tr3v3r commented 3 years ago

@harshmaur on iOS you have to use string port '9100' instead of 9100

This is my hack: image

harshmaur commented 3 years ago

@tr3v3r I tried using it, it always displays connected even with wrong ports and ips, EOD it doesnt work. I will give it another try to see if it works.

thecodecafe commented 4 months ago

@harshmaur did you ever get this to work on iOS?