Reputation: 1461
We are creating a bluetooth hardware device and want to store a unique identifier in the database so that multiple users won't try to connect to the same device. There is an Android and an iOS app.
It is my understanding that in iOS you can't access the MAC Address and the UUID provided is generated on the iOS side. We can add a characteristic providing a UUID, but is there a way to have a consistent identifier on iOS and Android without connecting to the bluetooth device?
Upvotes: 5
Views: 12078
Reputation: 437
If you have control over the hardware and what it advertises then you can include the mac address (or some other unique identifier) as service data or manufacturer-specific data. See https://developer.android.com/reference/android/bluetooth/le/ScanRecord.html on Android L or above. For lower Android versions you have to parse the scan record yourself, which is a bit of a pain.
For iOS see here: https://stackoverflow.com/a/25392156/4248895
For a quick proof of concept on Android you can use SweetBlue which handles the different OS versions for you under the hood. See:
http://idevicesinc.com/sweetblue/docs/api/com/idevicesinc/sweetblue/BleManagerConfig.ScanFilter.ScanEvent.html#serviceData
http://idevicesinc.com/sweetblue/docs/api/com/idevicesinc/sweetblue/BleManagerConfig.ScanFilter.ScanEvent.html#manufacturerData
Upvotes: 6
Reputation: 6885
For iOS:
BLE Device can advertise service UUIDs in their advertisement data.
[myPeripheralManager startAdvertising:@{ CBAdvertisementDataServiceUUIDsKey :
@[myFirstService.UUID, mySecondService.UUID] }];
In your iOS APP,you can scan for devices with specify service UUID:
[myCentralManager scanForPeripheralsWithServices:@[myFirstService.UUID, mySecondService.UUID] options:nil];
Your APP will only discover the BLE Device of these service UUIDs.
Upvotes: 0