dotintent / FlutterBleLib

Bluetooth Low Energy library for Flutter with support for simulating peripherals
Apache License 2.0
536 stars 197 forks source link

Is this library scanning explicitly for service UUIDs on iOS ? #472

Open HeikoMueller opened 4 years ago

HeikoMueller commented 4 years ago

For detecting peripheral services that are advertised from peripheral iOS devices in background mode, it is necessary to explicitly scan for these service UUIDs.

I include a list of service UUIDs in the startPeripheralScan method as arguments and these services are detected as long as the peripheral iOS device is not in background mode. As soon as I put the advertising iOS device into background mode, I do not receive scan results anymore.

For double-checking, I exchanged this library with "Flutter Reactive Ble" (which is not the best fit for my needs for other reasons) and received the service UUIDs that were sent from a peripheral iOS device without problem.

Does this library (FlutterBleLib) explicitly scan for the list of UUIDs that are given in the startPeripheralScan method as arguments as it is stated here in the iOS specifications ?

"All service UUIDs contained in the value of the CBAdvertisementDataServiceUUIDsKey advertisement key are placed in a special “overflow” area; they can be discovered only by an iOS device that is explicitly scanning for them"

https://developer.apple.com/library/archive/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/CoreBluetoothBackgroundProcessingForIOSApps/PerformingTasksWhileYourAppIsInTheBackground.html

mikolak commented 4 years ago

Hi!

I'd like to state that I do not have much knowledge about iOS, but my more knowledgable colleagues are unavailable for the time being. Could you help with the investigation perhaps?

The UUIDs are parsed and forwarded to BluetoothManager from RxBluetoothKit https://github.com/Polidea/MultiPlatformBleAdapter/blob/master/iOS/classes/BleModule.swift#L223 (lines 223-235)

For legacy reasons the RxBluetoothKit is incorporated instead of being downloaded as a dependency from pods (which will have to be fixed sometime in future). As far as I can tell, the library passes the uuids to RxCentralManager. https://github.com/Polidea/MultiPlatformBleAdapter/blob/master/iOS/RxBluetoothKit/BluetoothManager.swift#L151 ...which in turn passes the arguments to CBCentralManager, which is, as far as I know, part of the iOS system SDK. https://github.com/Polidea/MultiPlatformBleAdapter/blob/master/iOS/RxBluetoothKit/RxCBCentralManager.swift#L129

Does it seem correct so far?

I think there might be some restrictions on advertising from background, but I'm not sure - could it be that it was just a coincidence? Does nRF Connect, for example, reads those advertisements correctly?