How to transfer device UUID to CoreBluetooth infrastructure for client reconnection

I just wrote a simple application where I scan and connect to a peripheral (this is also an iOS device). However, the CBPeripheral object that I return from the ConnectPeripheral function does not have a device UUID and is always null. Now I'm trying to figure out where to install it so that it goes through. That's what I'm doing.

To advertise my service, I do

NSDictionary *advertisingDict=[NSDictionary dictionaryWithObject: services forKey:CBAdvertisementDataServiceUUIDsKey] [manager startAdvertising:advertisingDicts]; 

(From the framework, I understand that I cannot transfer the device UUID to the proposal. Correct me if I am wrong here)

My client is viewing the service and entering 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. I'm not sure how he understands which device should be connected when uuid is NULL. Also, what do I need to do if I want to connect again. How to fill this uuid?

+4
source share
1 answer

He has a job. You can pass it instead of the local device name as follows:

 [self.peripheralManager startAdvertising:@{CBAdvertisementDataLocalNameKey : *the UUID*}]; 

And in another device in the didDiscoverPeripheral function, you can get it like this:

 [advertisementData objectForKey:@"kCBAdvDataLocalName"] 
+1
source

All Articles