CBPeripheral name is sometimes null

孤街醉人 提交于 2019-12-21 04:04:08

问题


I'm working on developing an app to communicate with a Bluetooth LE peripheral. The peripheral I am testing with at the moment is one of these. The interesting thing is, sometimes when I discover it I get its proper name, "SimpleBLEPeripheral", sometimes I just get (null). There doesn't seem to be any command I can send to the CBPeripheral to force a read update on the name, so how can I ensure that I actually get the advertised name of the peripheral?


回答1:


If you get the name from the advertisingData NSDictionary it will always be the name that is in the advertising packet sent by the peripheral.

However, if you read the name property of a CBPeripheral object, that name may vary. We try to provide the best name know to us at the time. If we have not yet connected to the peripheral, we will provided the name from the advertising packet. If a connection to the peripheral has been made in the past, we will have read the GAP name. We consider the GAP name to be a 'better' name than what is in the advertising packet (due to the size constraints of the advertising packet).




回答2:


The only thing I have found that works around this problem is to start scanning and stop scanning, and eventually all the devices I expect to find in the physical space show up with non-nil names and non-nil UUIDs.



来源:https://stackoverflow.com/questions/12265028/cbperipheral-name-is-sometimes-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!