nativescript-community / nativescript-community/ble
bluetooth.connect with autoDiscoverAll hangs on iOS for BT Assigned Numbers
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 202
- Forks
- 79
- PR merge metrics
- No merged PRs in 30d
Description
I'm investigating an issue where bluetooth.connect() fails to resolve the promise when a serviceUUID falls under the Bluetooth Assigned Numbers list:
- BT specification: https://www.bluetooth.com/specifications/assigned-numbers/
my project versions:
{
"@nativescript/core": "^8.4.1",
"@nativescript-community/ble": "^3.1.11",
}
the call to bluetooth.connect():
await this.bluetooth.connect({
UUID: deviceUuid,
// autoDiscoverAll causes the hang... but only for those Assigned Number serviceUUIDs (link above)
autoDiscoverAll: true,
onConnected: (peripheral) => {
// the onConnected() callback is never called...
},
onDisconnected: function (peripheral) {
// onDisconnected IS called, on disconnect
}
});
I have tracked the problem down to:
https://github.com/nativescript-community/ble/blob/master/src/bluetooth.ios.ts#L1643-L1644
@bluetoothEnabled
@prepareArgs
public discoverCharacteristics(args: DiscoverCharacteristicsOptions) {
// ...
const sUUID = CBUUIDToString(service.UUID);
if (UUID === pUUID && sUUID === args.serviceUUID) {
// ...
}
// ...
}
the issue is the following comparison fails:
# "0000181a-0000-1000-8000-00805f9b34fb" == "181a"
sUUID === args.serviceUUID
args.serviceUUID is being be modified by the decorator prepareArgs() to a "Short UUID", if the service's UUID matches a Bluetooth Assigned Number of the form
const pattern = /0000(.{4})-0000-1000-8000-00805f9b34fb/;
however, sUUID returned by CBUUIDToString(service.UUID) is a "Long UUID"
Long vs Short UUIDs:
I'll work on a fix and submit a PR today hopefully...
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/bluetooth.ios.ts at discoverCharacteristics, then trace how the prepareArgs decorator changes args.serviceUUID. Reproduce the Assigned Numbers case with autoDiscoverAll enabled and verify that UUID comparison completes discovery and invokes onConnected instead of leaving the promise unresolved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100