Ios 核心蓝牙外围设备。名称为零

Ios 核心蓝牙外围设备。名称为零,ios,objective-c,core-bluetooth,bluetooth-lowenergy,Ios,Objective C,Core Bluetooth,Bluetooth Lowenergy,我只想知道附近蓝牙设备的名称。但是,peripheral.name始终为零。广告包装中的名称也始终为零。我在附近有7台设备。我能看见他们,但看不到他们的名字 我正在使用以下代码: [self.centralManager scanForPeripheralsWithServices:@[[CBUUID UUIDWithString:TRANSFER_SERVICE_UUID]] options:nil];

我只想知道附近蓝牙设备的名称。但是,
peripheral.name
始终为零。广告包装中的名称也始终为零。我在附近有7台设备。我能看见他们,但看不到他们的名字

我正在使用以下代码:

[self.centralManager scanForPeripheralsWithServices:@[[CBUUID UUIDWithString:TRANSFER_SERVICE_UUID]]
                                            options:nil];


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

{

    NSLog(@"Discovered %@ at %@", peripheral.name, RSSI);
    _discoveredPeripheral = peripheral;
    if(![self.mRemoteDevices containsObject:_discoveredPeripheral])
    {
        NSArray *peripherels = [self.centralManager retrievePeripheralsWithIdentifiers:@[_discoveredPeripheral.identifier]];
        [self.mRemoteDevices addObject:[peripherels objectAtIndex:0]];
        [self.mRemoteTable reloadData];
    }
    NSLog(@"retrieving peripherels: %@", self.mRemoteDevices);
}

事实上,在发现过程中,外围设备名称常常无法解析。但是,在您发现一个外围设备(可能已连接到它,我不确定这是否真的有必要)后,您很快就会在
cbperipheraldegate
callback
-peripal:didUpdateName:
中收到它的正确名称。假设不需要事先连接到外围设备,您应该等待此回调,并在回调代码中更新
mRemoteDevices
中适当设备的名称。

我不确定,但可能您必须传递这样的选项@{CBCentralManagerScanOptionAllowDuplicatesKey:[NSNumber numberWithBool:NO]}而不是nil。它有很多选择。我有这样的用法。在你没有名字或广告数据之前,尽量不要连接。如果我没记错的话,这些信息是一块一块地传来的,并且可能会在每次传来新信息时出现。到目前为止,您可能必须更改“允许重复”键参数。