0

I'm using flutter_blue_plus package which is almost same with flutter_blue. When I test with iphone 13 mini connected with mac book xcode, my app scans bluetooth devices well. But when I extract my app to .ipa and install the app using xcode, my iphone 13 mini(which is not connected to mac book) not scan bluetooth devices anymore. Of course I've checked that I give same permission to the iphone both of the test. Is there any suggestion for test or anyone experienced same situation?
I'm very beginner of flutter and ios development (I just started it from a month ago), so please give me any advice if you have about this bluetooth problem..

My scan function is in the background mode, and I checked the scanned devices using snack bar. But I think it is not the problem, the app works well when I test with xcode and the iphone is connected to mac.

I added a part of my code for your information.

(My function for BLE Scanning)

    Future<void> initialScanning() async {
      // ios execute this function with .ipa installed but skips scanning.
      final FlutterBluePlus flutterBlue = FlutterBluePlus.instance;
      // Start scanning
      flutterBlue.startScan(timeout: Duration(seconds: _firstScanDuration));
      // Listen to scan results
      var subscription = flutterBlue.scanResults.listen((results) async {
        // Find the device with the name and Register
        for (ScanResult r in results) {
          print('${r.device.name} rssi: ${r.rssi}');
          if (r.device.name == 'raspberrypi') {
            if (!devices.contains(r.device)) {
              devices.add(r.device);
              print('device added!!!!');
            }
          }
        }
        for (BluetoothDevice device in devices) {
          if (!registeredDevices.contains(device.id.toString())) {
            registeredDevices.add(device.id.toString());
            await someBleRegister(device);
          }
        }
      });
      // Stop scanning
      flutterBlue.stopScan();
    }

(onEvent function for flutter_foreground_task)

    @override
    Future<void> onEvent(DateTime timestamp, SendPort? sendPort) async {
      if (_eventCount == 0) {
        await initialScanning();
      } else {
        print('number of devices: ${someBles.length}');
        for (SomeBle ble in someRegisteredBles) {
          await someBleReadAndWrite(ble);
        }
      }
Sunghoon Cho
  • 86
  • 1
  • 7
  • Please provide enough code so others can better understand or reproduce the problem. – Community Sep 13 '22 at 15:42
  • Looking at the code, I don't see any way to pass the list of service UUIDs to scan for. It has a property called `serviceUuidsArray`, but I don't see any discussion of how to set it. You'll need to set that to the list of UUIDs to scan for in order for this to work in the background. See https://stackoverflow.com/questions/26604177/bluetooth-le-device-scan-in-background-from-ios – Rob Napier May 14 '23 at 15:53
  • Thanks to reply my old question. Actually I solved my problem about 3 month after the question. Yes, maybe your point was the reason. I had changed the flutter package to `flutter_reactive_ble` which can easily use the target UUID of service and characteristics for background `onEvent` function (read and write data). And I moved scanning and register code to foreground. So, now it works. – Sunghoon Cho May 16 '23 at 03:57

0 Answers0