4

我刚刚编写了一个简单的应用程序,我在其中扫描并连接到外围设备(这也是一个 IOS 设备)。但是,我从 ConnectPeripheral 函数返回的 CBPeripheral 对象没有设备 UUID,并且它始终为空。现在我试图了解我在哪里设置它以便它通过。这就是我正在做的事情。

为了宣传我正在做的服务

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

(从框架我了解到我无法在广告包中传递设备 UUID。如果我在这里错了,请纠正我)

我的客户端扫描服务并进入功能

centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral

正如预期的那样,peripheral.uuid 为空。如果我在这个外围设备上调用 connectPeripheral,它也可以正常工作。我不确定当 uuid 为空时它如何理解要连接的设备。另外,如果我想稍后重新连接,我需要做什么。我如何填写这个 uuid?

4

1 回答 1

1

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"]
于 2013-05-16T09:04:18.127 回答