kechankrisna / pos_printer_manager

GNU General Public License v3.0
13 stars 53 forks source link

Problem printing Ios #4

Open renanzdm opened 3 years ago

renanzdm commented 3 years ago

I'm trying to use the package to print tickets. On android it's working perfectly, but on ios it connects but can't print

[✓] Flutter (Channel unknown, 2.2.1, on macOS 11.4 20F71 darwin-x64, locale pt-BR) [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3) [✓] Xcode - develop for iOS and macOS [✓] Chrome - develop for the web [✓] Android Studio (version 4.2) [✓] VS Code (version 1.57.0) [✓] Connected device (3 available)

filterBlacklist =     (
);
filterWhitelist =     (
);
restrictWeb = 1;
useContentFilter = 0;
useContentFilterOverrides = 0;
whitelistEnabled = 0;

} WF: _WebFilterIsActive returning: NO height = 474.0 width = 576.0 Got snapshot flutter: isConnected true didDiscoverServices Found service: 180A Found service: 180F Found service: 18F0 Found service: E7810A71-73AE-499D-8C15-FAA9AEF0C3F2 4 didDiscoverCharacteristicsForService 5 didDiscoverDescriptorsForCharacteristic peripheral uuid:546EDE68-387C-BA7C-8323-B20B18F1E593 service uuid:0000180a-0000-1000-8000-00805f9b34fb uuid: 00002a23-0000-1000-8000-00805f9b34fb value: (null) peripheral uuid:546EDE68-387C-BA7C-8323-B20B18F1E593 service uuid:0000180f-0000-1000-8000-00805f9b34fb uuid: 00002a19-0000-1000-8000-00805f9b34fb value: (null) peripheral uuid:546EDE68-387C-BA7C-8323-B20B18F1E593 service uuid:000018f0-0000-1000-8000-00805f9b34fb uuid: 00002af0-0000-1000-8000-00805f9b34fb value: (null) uuid: 00002af1-0000-1000-8000-00805f9b34fb value: (null) peripheral uuid:546EDE68-387C-BA7C-8323-B20B18F1E593 service uuid:e7810a71-73ae-499d-8c15-faa9aef0c3f2 uuid: bef8d6c9-9c21-4c9e-b632-bd58c1009f9f value: (null) flutter: Error : Bad state: No element

kechankrisna commented 3 years ago

I'm trying to use the package to print tickets. On android it's working perfectly, but on ios it connects but can't print

[✓] Flutter (Channel unknown, 2.2.1, on macOS 11.4 20F71 darwin-x64, locale pt-BR) [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3) [✓] Xcode - develop for iOS and macOS [✓] Chrome - develop for the web [✓] Android Studio (version 4.2) [✓] VS Code (version 1.57.0) [✓] Connected device (3 available)

filterBlacklist =     (
);
filterWhitelist =     (
);
restrictWeb = 1;
useContentFilter = 0;
useContentFilterOverrides = 0;
whitelistEnabled = 0;

} WF: _WebFilterIsActive returning: NO height = 474.0 width = 576.0 Got snapshot flutter: isConnected true didDiscoverServices Found service: 180A Found service: 180F Found service: 18F0 Found service: E7810A71-73AE-499D-8C15-FAA9AEF0C3F2 4 didDiscoverCharacteristicsForService 5 didDiscoverDescriptorsForCharacteristic peripheral uuid:546EDE68-387C-BA7C-8323-B20B18F1E593 service uuid:0000180a-0000-1000-8000-00805f9b34fb uuid: 00002a23-0000-1000-8000-00805f9b34fb value: (null) peripheral uuid:546EDE68-387C-BA7C-8323-B20B18F1E593 service uuid:0000180f-0000-1000-8000-00805f9b34fb uuid: 00002a19-0000-1000-8000-00805f9b34fb value: (null) peripheral uuid:546EDE68-387C-BA7C-8323-B20B18F1E593 service uuid:000018f0-0000-1000-8000-00805f9b34fb uuid: 00002af0-0000-1000-8000-00805f9b34fb value: (null) uuid: 00002af1-0000-1000-8000-00805f9b34fb value: (null) peripheral uuid:546EDE68-387C-BA7C-8323-B20B18F1E593 service uuid:e7810a71-73ae-499d-8c15-faa9aef0c3f2 uuid: bef8d6c9-9c21-4c9e-b632-bd58c1009f9f value: (null) flutter: Error : Bad state: No element

Did you try network print or bluetooth print?

renanzdm commented 3 years ago

Bluetooth printer

renanzdm commented 3 years ago

Hello I'm suspicious that the problem may be in my printer, which is a cheap and generic one. Did you manage to perform tests using Iphone?

kechankrisna commented 3 years ago

Hello I'm suspicious that the problem may be in my printer, which is a cheap and generic one. Did you manage to perform tests using Iphone?

I have tested BLE on ios already, it was working fine. So now I am not sure what the problem is.

renanzdm commented 3 years ago

Do you remember which printer model you used? I'm using a generic portable printer

kechankrisna commented 3 years ago

Do you remember which printer model you used? I'm using a generic portable printer

These are models I used to test: AW 5809dd mini thermal printer and Xprinter 80mm Thermal Receipt Printer Bluetooth

renanzdm commented 3 years ago

Captura de Tela 2021-06-28 às 14 42 00 Hey man, I was doing some tests and I realized that when you find the services you check if it's primary, but I don't know if it's specific to the printer I'm using, it shows several services as being primary. Afterwards you check if it has the possibility to write in this feature, but in some services this possibility is null, so the error

YOUR CODE

} else if (Platform.isIOS) {
        var services = (await fbdevice.discoverServices());
        var service = services.firstWhere((e) => e.isPrimary);
        var charactor =
            service.characteristics.firstWhere((e) => e.properties.write);
        await charactor?.write(data, withoutResponse: true);
      }
    }

MY CODE

}else if (Platform.isIOS) {
        fblue.BluetoothCharacteristic printerService;
        List<fblue.BluetoothService> services =
            (await fbdevice.discoverServices());
        for (var service in services) {
          if (service.isPrimary) {
            for (var character in service.characteristics) {
              if (character.properties.write) {
                printerService = character;
              }
            }
          }
        }
        final len = data.length;
        List<List<int>> chunks = [];
        for (var i = 0; i < len; i += 100) {
          var end = (i + 100 < len) ? i + 100 : len;
          chunks.add(data.sublist(i, end));
        }
        for (var i = 0; i < chunks.length; i++) {
          await printerService?.write(chunks[i]);
        }

I will be very grateful if you can do some tests if this way works well for you too

kechankrisna commented 3 years ago

Captura de Tela 2021-06-28 às 14 42 00 Hey man, I was doing some tests and I realized that when you find the services you check if it's primary, but I don't know if it's specific to the printer I'm using, it shows several services as being primary. Afterwards you check if it has the possibility to write in this feature, but in some services this possibility is null, so the error

YOUR CODE

} else if (Platform.isIOS) {
        var services = (await fbdevice.discoverServices());
        var service = services.firstWhere((e) => e.isPrimary);
        var charactor =
            service.characteristics.firstWhere((e) => e.properties.write);
        await charactor?.write(data, withoutResponse: true);
      }
    }

MY CODE

}else if (Platform.isIOS) {
        fblue.BluetoothCharacteristic printerService;
        List<fblue.BluetoothService> services =
            (await fbdevice.discoverServices());
        for (var service in services) {
          if (service.isPrimary) {
            for (var character in service.characteristics) {
              if (character.properties.write) {
                printerService = character;
              }
            }
          }
        }
        final len = data.length;
        List<List<int>> chunks = [];
        for (var i = 0; i < len; i += 100) {
          var end = (i + 100 < len) ? i + 100 : len;
          chunks.add(data.sublist(i, end));
        }
        for (var i = 0; i < chunks.length; i++) {
          await printerService?.write(chunks[i]);
        }

I will be very grateful if you can do some tests if this way works well for you too

Thank you for your suggestion, I will recheck it in my code to test it.