CBPeripheral名称有时为null [英] CBPeripheral name is sometimes null

查看:508
本文介绍了CBPeripheral名称有时为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一款与蓝牙LE外设进行通信的应用。我正在测试的外围设备是这些之一。有趣的是,有时当我发现它时,我得到它的正确名称,SimpleBLEPeripheral,有时我只是得到(null)。似乎没有任何命令可以发送到CBPeripheral以强制对名称进行读取更新,那么如何确保我实际获得外围设备的广告名称?

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?

推荐答案

如果从advertisingData NSDictionary获取名称,它将始终是外围设备发送的广告数据包中的名称。

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.

但是,如果您读取CBPeripheral对象的name属性,则该名称可能会有所不同。我们试图在当时向我们提供最好的名字。如果我们尚未连接到外围设备,我们将从广告包中提供名称。如果过去已与外围设备建立连接,我们将阅读GAP名称。我们认为GAP名称比广告包中的名称更好(由于广告包的大小限制)。

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).

这篇关于CBPeripheral名称有时为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆