januslo / react-native-bluetooth-escpos-printer

React-Native plugin for the bluetooth ESC/POS & TSC printers.
MIT License
349 stars 409 forks source link

App crash or get disconnected after 6-7 tickets #220

Open usfslk opened 1 year ago

usfslk commented 1 year ago
"react-native": "0.70.6",
"react-native-esc-pos-printer": "^2.3.0",

This is my code

 componentWillUnmount() {
    if (this.unsubscriber) {
      this.unsubscriber()
    }
  }

  async monitorPrinter() {
    try {
      console.log('Start monitoring ...');
      this.setState({ loading: true })

      await EscPosPrinter.init({
        target: this.state.printer.target,
        seriesName: getPrinterSeriesByName(this.state.printer.name),
      });
    }
    catch (error) {
      console.log(error)
    }

    this.unsubscriber = EscPosPrinter.addPrinterStatusListener((status) => {
      this.setState({ status: status, loading: false })
      if (status.connection === 'DISCONNECT') {
        this.context.setAppState(`No device connected`)
        this.setState({ status: null })
      }
    })
    if (this.state.status === null) {
      EscPosPrinter.startMonitorPrinter(5)
        .then(() => console.log('Start monitor success!'))
        .catch((e) => this.setState({ error: e.message, loading: false }))
    }
  }

  scanPrinter = () => {
    this.setState({ loading: true, error: null })
    EscPosPrinter.discover()
      .then((printers) => {
        if (printers.length === 0) {
          this.setState({ loading: false, error: 'No printers found. Please try again.' })
        }
        if (printers[0]) {
          this.setState({ printer: printers[0], loading: false })
          this.context.setAppState(`Successfully connected to ${printers[0].name}`)
          this.context.setPrinter(printers[0])
          console.log('Connected');
          this.monitorPrinter()
        } else {
          this.setState({ loading: false, error: 'No printers found. Please try again.' })
        }
      })
      .catch(console.log);
  }

when the app crash I got the following error on xcode

+[UIInputViewSetPlacementInvisible placementWithPlacement:]: Should not be called with an invisible placement

2023-03-17 14:13:10.360947+0100 epsontest[20442:688621] Removing EASession 585D04A4-7079-4564-9DF8-2464180ECA65 from list of sessionUUIDs
epsontest(20442,0x170773000) malloc: *** error for object 0x69003a00610074: pointer being freed was not allocated
epsontest(20442,0x170773000) malloc: *** set a breakpoint in malloc_error_break to debug
dyld4 config: DYLD_LIBRARY_PATH=/usr/lib/system/introspection DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib
farhanaAzizan commented 12 months ago

any update on this issue ? Im getting the same issue also, the app close down after printing for the first time and when the app being open again the printer already disconnected