Reputation: 41
I just wrote a simple app where I scan and connect to peripheral (which is also an IOS device). However the CBPeripheral object I get back from ConnectPeripheral function does not have the device UUID and it's always null. Now I am trying to understand where do I set it so that it gets passed. Here is what I am doing.
To advertise my service I am doing
NSDictionary *advertisingDict=[NSDictionary dictionaryWithObject: services forKey:CBAdvertisementDataServiceUUIDsKey]
[manager startAdvertising:advertisingDicts];
(From the framework I understand that I cannot pass the device UUID in the advertising packet. Correct me if I am wrong here)
My client scan for the service and gets into the function
centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral
And as expected the peripheral.uuid is null. If I call connectPeripheral on this peripheral it works fine too. I am not sure how it understands which device to connect when the uuid is null. Also what would I need to do If I want to reconnect later. How do I fill this uuid?
Upvotes: 4
Views: 2134
Reputation: 555
It has a work around. You can pass it instead of the local name of the device like this:
[self.peripheralManager startAdvertising:@{CBAdvertisementDataLocalNameKey : *the UUID*}];
And in the other device in the didDiscoverPeripheral function you can get it like this:
[advertisementData objectForKey:@"kCBAdvDataLocalName"]
Upvotes: 1