简体   繁体   English

核心蓝牙问题

[英]Problems with Core Bluetooth

I am making an app in which an iOS device has to be peripheral and central at the same time. 我正在制作一个应用程序,其中iOS设备必须同时处于外围设备和中央设备。 When it discovers a peripheral, sometimes its name is the model (eg iPhone) as opposed to the actual name (eg My iPhone). 当发现外围设备时,有时它的名称是型号(例如iPhone),而不是实际名称(例如My iPhone)。 In this case, the UUID is there instead (usually it's (null) when the name is the actual name). 在这种情况下,UUID在那里(通常,当名称是实际名称时,它是(null) )。 I have set the name correctly in startAdvertising: and when this happens the real name isn't given by the corresponding key in advertisementData 我已经在startAdvertising:正确设置了名称startAdvertising:当发生这种情况时, 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). 当应用程序移至后台时,会将adv数据放入哈希中,以便与单个应用程序同时运行带有corebluetooth的多个应用程序时具有相同的体验(因为iPhone本身只能播发有限数量的数据)。 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. 但是,我注意到,一旦在前台看到该设备,如果该应用程序移至后台,您仍然可以看到大多数adv数据。 Let me know if you have questions. 如果您有任何问题,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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