thiendangit / react-native-thermal-receipt-printer-image-qr

React native thermal receipt printer
https://www.npmjs.com/package/react-native-thermal-receipt-printer-image-qr
119 stars 80 forks source link

NetPrinter not working well for iOS #111

Open ShinThantAein opened 9 months ago

ShinThantAein commented 9 months ago

I'd like to print base64 image using printImageBase64() function. In Android, it's working well. In iOS, successfully pod installed and build is successful. But when run on my device and call NetPrinter related functions, it's getting TCP Disconnected error continuously and app stopped after some time.

react : 18.2.0 react-native : 0.72 react-native-thermal-receipt-printer-image-qr : 0.1.11

111

import React, {useEffect} from 'react'; import { SafeAreaView, ScrollView, View, Text, StatusBar, } from 'react-native'; import { NetPrinter, NetPrinterEventEmitter, RN_THERMAL_RECEIPT_PRINTER_EVENTS } from 'react-native-thermal-receipt-printer-image-qr';

const App = () => {

useEffect(() => { const initPrinterFunc = async () => { NetPrinter.init().then(() => { console.log("initialized Net printer...") }); const results = await NetPrinter.getDeviceList(); console.log("results >> ", results); };

initPrinterFunc();

}, []);

useEffect(() => {

NetPrinterEventEmitter.addListener(
  RN_THERMAL_RECEIPT_PRINTER_EVENTS.EVENT_NET_PRINTER_SCANNED_SUCCESS,
  (printers) => {
    console.log("Scanned >> ", printers);
    if (printers && printers.length > 0 && printers[0].host) {
      connectNetPrinter(printers[0].host);
    }
  },
);
(async () => {
    const results = await NetPrinter.getDeviceList();
    console.log("2 results >> ", results);
  })();

return () => { NetPrinterEventEmitter.removeAllListeners( RN_THERMAL_RECEIPT_PRINTER_EVENTS.EVENT_NET_PRINTER_SCANNED_SUCCESS, ); NetPrinterEventEmitter.removeAllListeners( RN_THERMAL_RECEIPT_PRINTER_EVENTS.EVENT_NET_PRINTER_SCANNED_ERROR, ); }; }, []);

return ( <>

  <SafeAreaView>
    <ScrollView>
      <View>
        <Text>Hello World</Text>
      </View>
    </ScrollView>
  </SafeAreaView>
</>

); };

export default App;