chipweinberger / flutter_blue_plus

Flutter plugin for connecting and communicationg with Bluetooth Low Energy devices, on Android, iOS, macOS
Other
727 stars 442 forks source link

[Help]: FlutterBluePlus.systemDevices is not working on iOS 18. #996

Open anhvu2503 opened 1 day ago

anhvu2503 commented 1 day ago

Requirements

Have you checked this problem on the example app?

Yes

FlutterBluePlus Version

1.32.12

Flutter Version

3.19.5

What OS?

iOS

OS Version

IOS 18

Bluetooth Module

Nordic nRF52832

What is your problem?

When my phone is updated to the latest iOS 18 version, and I use FlutterBluePlus.systemDevices in my app to retrieve connected system devices, the result returns an empty list. However, when using a phone with an earlier version, everything works fine.

Logs

No logs.
chipweinberger commented 1 day ago

seems like it might be a new privacy restriction in iOS:

https://www.reddit.com/r/iOSProgramming/comments/1dctwmo/whats_with_the_new_bluetooth_privacy_features/

chipweinberger commented 1 day ago

In FBP systemDevices is a wrapper around retrieveConnectedPeripheralsWithServices

We use the Generic Access Service 0x1800, but perhaps Apple has blocked this in iOS because it basically returns all devices.

Try forking FBP and looking for a specific service instead. We might need to update the API to be compatible with iOS 18.

        else if ([@"getSystemDevices" isEqualToString:call.method])
        {
            // Cannot pass blank UUID list for security reasons.
            // Assume all devices have the Generic Access service 0x1800
            CBUUID* gasUuid = [CBUUID UUIDWithString:@"1800"];

            // this returns devices connected by *any* app
            NSArray *periphs = [self.centralManager retrieveConnectedPeripheralsWithServices:@[gasUuid]];

            // Devices
            NSMutableArray *deviceProtos = [NSMutableArray new];
            for (CBPeripheral *p in periphs) {
                [deviceProtos addObject:[self bmBluetoothDevice:p]];
            }

            // See BmDevicesList
            NSDictionary* response = @{
                @"devices": deviceProtos,
            };

            result(response);
        }
chipweinberger commented 1 day ago

if you fix this issue, please open a PR.

I don't plan to fix it myself.

if new api is needed, let's do a breaking change FlutterBluePlus.systemDevices({Guid? serviceUuid})

the serviceUuid will be required on iOS only, and ignored on Android.

anhvu2503 commented 1 day ago

Thank you for providing the information.
I will try this approach.
Have a great day!