Connecting to a bluetooth machine with pairing in iOS in Flutter

Spread the love

In my Flutter app, I’ve a service that’s supposed to connect with a Bluetooth machine with pairing. I take advantage of flutter_blue_plus for Bluetooth performance. All the things works completely on Android, however on iOS, it is unimaginable to provoke pairing manually. Subsequently, I attempt to learn a attribute, and I even get a pop-up for PIN enter, however after that, the connection all the time breaks, although the machine seems within the paired record. Is it even doable to implement utilizing solely flutter and flutter blue?

  Future<BluetoothDevice?> _connectToIOS(BluetoothDevice machine) async {
    attempt {
      await machine.join(
        // autoConnect: true,
        timeout: const Period(
          seconds: 30,
      ); attention(
        (occasion) async {
          print("occasion $occasion");
          if (occasion == BluetoothConnectionState.linked) {
            await _discoverServices(machine);
        onError: (error) {
          print("join error $error");
        onDone: () {

      return machine;
    } catch (e) {
      print("hook up with IOS error $e");
      return null;
 Future<void> _discoverServices(BluetoothDevice machine) async {
    attempt {
      last companies = await machine.discoverServices();
      print("Providers $companies");
      for (BluetoothService service in companies) {
        if (service.uuid.toString() == SERVICE_UUID) {
          BluetoothCharacteristic? writeCharacteristic;
          BluetoothCharacteristic? readCharacteristic;

          for (BluetoothCharacteristic attribute
              in service.traits) {
            if (attribute.uuid.toString() == WRITE_CHAR_UUID) {
              writeCharacteristic = attribute;
            if (attribute.uuid.toString() == READ_CHAR_UUID) {
              readCharacteristic = attribute;

          if (readCharacteristic != null) {
            _readCharacteristic = readCharacteristic;
            await _readCharacteristic!.setNotifyValue(true);
            _valueStream = readCharacteristic.lastValueStream;

          if (writeCharacteristic != null) {
            _writeCharacteristic = writeCharacteristic;
    } catch (e) {
      print("error $e");

Leave a Reply

Your email address will not be published. Required fields are marked *