不正确BLE外设名称与iOS [英] Incorrect BLE Peripheral Name with iOS

查看:906
本文介绍了不正确BLE外设名称与iOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写的iOS应用程序与BLE设备进行通信。该设备可以(而不是在BLE连接)更改连接之间的名字,但iOS的拒绝更改设备名称。

I am writing an iOS app to communicate with a BLE device. The device can change names between connections (not during the BLE connection), but iOS refuses to change the device name.

例如:我可以连接到该设备时,它的名字是SadName。我请断开连接,关闭应用程序等,并更改设备的名称HappyName。但是,当我扫描设备的iOS仍是外围名SadName。

For example: I can connect to the device when its name is SadName. I disconnect it, shut down the app, etc. and change the device's name to HappyName. But, when I scan for devices iOS still shows the peripheral name as SadName.

如果我调试应用程序,查看:

If I debug the app and look at:

 (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI

peripheral.name的值是SadName,所以我不认为这是我在code不正确的是间preting东西。我应该提到,当我扫描设备,我的code是:

the value of peripheral.name is SadName so I don't think that it is something that I am interpreting incorrectly in code. I should mention that when I scan for devices, my code is:

[self.CM scanForPeripheralsWithServices:nil options:0]; // Start scanning 

我猜测,这很简单,因为设备的UUID是相同的,所以iOS的是从它的缓存设备列表中拉了,但我要改写。

I am guessing that it is simply because the devices UUID is the same so iOS is pulling it from its cached devices list, but I want to override that.

的思考?对不起,我是新来的iOS。
干杯 -
MSchmidtbauer

Thoughts? Sorry, I am new to iOS. Cheers - MSchmidtbauer

推荐答案

的iOS SDK的API CoreBluetooth不提供方法来强制刷新外围名。

The CoreBluetooth API of iOS SDK does not provide a way to force refresh the peripheral name.

目前,它是不可行的iOS中使用peripheral.name时,该设备名称在BLEdevice变化。

苹果表明通过指定CBUUID对象(包含一个或多个服务的UUID)传递给scanForPeripheralsWithServices列表来扫描特定设备:

Apple suggests to scan for a specific device by specifying a list of CBUUID objects (containing one or more service UUIDs) that you pass to scanForPeripheralsWithServices:

NSArray *services = @[[CBUUID UUIDWithString: @"2456e1b9-26e2-8f83-e744-f34f01e9d701"] ]; // change to your service UUID!
NSDictionary *dictionary = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:1] forKey:CBCentralManagerScanOptionAllowDuplicatesKey];

[self.manager scanForPeripheralsWithServices:services options:dictionary];

此降低didDiscoverPeripheral的呼叫数。不要只是通过零至scanForPeripheralsWithServices。它还允许你的应用程序扫描外设在后台状态时。

This reduces the number of calls of didDiscoverPeripheral. Do not just pass nil to scanForPeripheralsWithServices. It also allows your app to scan for a peripheral when in background state.

如果你正在寻找一种方式来广播建立连接之前可用的动态信息,您可以使用广告或扫描响应数据即可。外设可配置为广播名为本地名称制造商特定数据项即可。这个数据在didDiscoverPeripheral速效

If you are looking for a way to broadcast dynamic information that's available before a connection is established, you can use the Advertise or Scan Response Data. The peripheral can be configured to broadcast the entries called Local Name and Manufacturer Specific Data. This data is availabe in the didDiscoverPeripheral:

- (void)centralManager:         (CBCentralManager *)central
 didDiscoverPeripheral:  (CBPeripheral *)peripheral
     advertisementData:      (NSDictionary *)advertisementData
                  RSSI:         (NSNumber *)RSSI {
NSString *localName = [advertisementData objectForKey:CBAdvertisementDataLocalNameKey];
NSData *manufacturerData = [advertisementData objectForKey:CBAdvertisementDataManufacturerDataKey];
NSLog(@"Local: name: %@", localName); 
NSLog(@"Manufact. Data: %@", [manufacturerData description]);
}

本地名称是一个NSString ,所以在此提出的BLE设备上只写可打印字符。 制造商的数据是一个NSData ,这可以包含任意字节值,所以你甚至可以有二进制数据在这里。

Local Name is an NSString, so write only printable characters on the BLE device in this filed. Manufacturer Data is an NSData, this can contain any byte value, so you can even have binary data here.

根据所使用的BLE设备上,本地名称和制造商特定数据的长度是有限的。

Depending on the BLE device you use, the length of Local Name and Manufacturer Specific Data is limited.

在我的BLE的设备,我公司可以派128位服务的UUID和8字符的本地名称与广告数据。制造商特定数据进入扫描响应数据,可以是29个字节。

On my BLE device,I can send the 128 Bit service UUID and a 8 char Local Name with the Advertise Data. The Manufacturer Specific Data goes into the Scan Response Data and can be 29 bytes long.

有关使用Adv./Scan响应数据的好处是,它可以在这个BLE设备上更改,恕不电源循环。

Good thing about using the Adv./Scan Response Data is, it can change on this BLE device without a power cycle.

建议:


  1. 使用服务的UUID过滤扫描时(UUID必须是广告数据的一部分!我忽略它在上面的描述)

  2. 使用广告/扫描响应数据进行进一步的过滤

  3. 忘记peripheral.name只要没有可用的确定性刷新

这篇关于不正确BLE外设名称与iOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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