iOS CoreBluetooth无法在iPad Air中扫描服务 [英] iOS CoreBluetooth not scanning for services in iPad Air

查看:148
本文介绍了iOS CoreBluetooth无法在iPad Air中扫描服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个连接到BLE外围设备并从中接收数据的应用程序。

I'm working on a app that connects to a BLE peripheral and receives data from it.

它扫描外围设备,找到外围设备,发现服务,并如果找到正确的服务,它将接收数据。

It scans for peripherals, finds a peripheral, discovers services, and if the right service is found, it receives data.

它在iPhone 5上运行良好,但是当我在iPad Air上运行时,它可以连接,但不能发现任何服务,并且不接收任何数据。两种设备都运行iOS 7.0.4

It works great on an iPhone 5, but when I run it on an iPad Air it connects , but doesn't discover any services, and receives no data. Both devices run iOS 7.0.4

这是代码的一些相关部分

This is some of the relevant parts of the code

- (void)startScan
{

    [manager scanForPeripheralsWithServices:nil options:nil];
}

- (void)stopScan
{
    [manager stopScan];
}



- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral    *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
{
NSLog(@"Did discover peripheral. peripheral: %@ rssi: %@, id: %@ advertisementData: %@ ", peripheral, RSSI, peripheral.identifier, advertisementData);

    if(![self.dicoveredPeripherals containsObject:peripheral])
        [self.dicoveredPeripherals addObject:peripheral];

    [manager retrievePeripheralsWithIdentifiers:[NSArray arrayWithObject:(id)peripheral.identifier]];

    [manager connectPeripheral:peripheral options:[NSDictionary dictionaryWithObject:   [NSNumber numberWithBool:YES] forKey:CBConnectPeripheralOptionNotifyOnDisconnectionKey]];
}


- (void)centralManager:(CBCentralManager *)central didRetrievePeripherals:(NSArray *)peripherals
{
    NSLog(@"Retrieved peripheral: %lu - %@", (unsigned long)[peripherals count], peripherals);
    [self stopScan];

    /* If there are any known devices, automatically connect to it.*/
    if([peripherals count] >= 1)
    {
        testPeripheral = [peripherals objectAtIndex:0];

        [manager connectPeripheral:testPeripheral
                       options:[NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:CBConnectPeripheralOptionNotifyOnDisconnectionKey]];
    }
}


- (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral
{
    NSLog(@"Did connect to peripheral: %@", peripheral);
    [self.delegate statusMessage:[NSString stringWithFormat:@"Did connect to peripheral: %@\n", peripheral]];

    [peripheral setDelegate:self];
    [peripheral discoverServices:nil];
}


- (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error
{
for (CBService *service in peripheral.services) {
        NSLog(@"discovered service [%@]",service.UUID);
        [peripheral discoverCharacteristics:nil forService:service];
    }
}

iPhone 5的日志输出为:

The log output on the iPhone 5 is :

Did discover peripheral. peripheral: <CBPeripheral: 0x14587320 identifier = 3EE10DD6-99CD-  7E9C-C492-087CE3B980E6, Name = "BLE Sens", state = disconnected> rssi: -53, id:     <__NSConcreteUUID 0x145f82f0> 3EE10DD6-99CD-7E9C-C492-087CE3B980E6 advertisementData: {
kCBAdvDataChannel = 38;
kCBAdvDataIsConnectable = 1;
kCBAdvDataLocalName = BLESensor;
kCBAdvDataServiceUUIDs =     (
    "Unknown (<fff0>)"
);
kCBAdvDataTxPowerLevel = 0;
} 

Did connect to peripheral: <CBPeripheral: 0x14587320 identifier = 3EE10DD6-99CD-7E9C-C492-087CE3B980E6, Name = "BLE Sens", state = connected>

Connected
discovered service [Device Information]
discovered service [Unknown (<fff0>)]
discovered service [Unknown (<ffe0>)]
Service found with UUID: Device Information

在iPadAir上,它仅到达连接的部分,并且找不到服务:

On the iPadAir it just gets to the connected part and no services are found :

Did discover peripheral. peripheral: <CBPeripheral: 0x1700a1440 identifier = 23890BB4-FB07-AA1A-8D4F-B1427C859447, Name = "BLE Sens", state = disconnected> rssi: -60, id:   <__NSConcreteUUID 0x17802f740> 23890BB4-FB07-AA1A-8D4F-B1427C859447 advertisementData: {
    kCBAdvDataChannel = 39;
kCBAdvDataIsConnectable = 1;
kCBAdvDataLocalName = BLESensor;
kCBAdvDataServiceUUIDs =     (
    "Unknown (<fff0>)"
);
kCBAdvDataTxPowerLevel = 0;
} 

Did connect to peripheral: <CBPeripheral: 0x1700a1440 identifier = 23890BB4-FB07-AA1A-8D4F-B1427C859447, Name = "BLE Sens", state = connected>
 Connected 


推荐答案

Apple承认这是一个iOS 7.0中的问题。他们承诺在iOS 7.1中解决该问题。我在iOS 7.1上进行了测试,并解决了该问题。

Apple admitted that this was an issue in iOS 7.0 . They promised to solve it in iOS 7.1. I tested it with iOS 7.1 , and it is solved.

这篇关于iOS CoreBluetooth无法在iPad Air中扫描服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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