简体   繁体   中英

Problems with Core Bluetooth

I am making an app in which an iOS device has to be peripheral and central at the same time. When it discovers a peripheral, sometimes its name is the model (eg iPhone) as opposed to the actual name (eg My iPhone). In this case, the UUID is there instead (usually it's (null) when the name is the actual name). I have set the name correctly in startAdvertising: and when this happens the real name isn't given by the corresponding key in advertisementData

How do I make sure that the real name is always there?

This is how I'm setting the name:

[self.peripheralManager startAdvertising:@{ CBAdvertisementDataLocalNameKey : [[UIDevice currentDevice] name], CBAdvertisementDataServiceUUIDsKey : @[SERVICE_UUID] }];

Unless the app that is advertising is constantly in the foreground, there are no guarantees that the advertisement data (other than specific services you're searching for) will be visible. The adv data is put into a hash when the app moves to the background in order to have the same experience when running multiple apps with corebluetooth simultaneously vs a single app (since the iPhone itself can only advertise a finite amount of data). However, I have noticed that once the device is seen in the foreground, if the app moves to the background you will still be able to see most of the adv data. Let me know if you have questions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM