如题,ble加了ancs后,通过app能够连接并配对成功。如果用户关闭app,再次打开会搜索不到蓝牙设备。这时候要连接该怎么办?大牛们有没有做过ancs的,提供下思路。

解决方案 »

  1.   

    通过下面代码可以找到已经配对过的设备。但是链接不起来    NSArray *bleArray = [NSArray arrayWithObjects:[CBUUID UUIDWithString:@"180A"], nil];
        NSArray *retrivedArray = [delegate.sensor.manager retrieveConnectedPeripheralsWithServices:bleArray];
        
        NSLog(@"retrivedArray:\n%@",retrivedArray);
        
        for (CBPeripheral* peripheral in retrivedArray) { // 只有一个配对的设备,暂时不考虑多个
    //        [delegate.sensor connect:peripheral];
            
            [delegate.sensor.manager connectPeripheral:peripheral options:@{CBConnectPeripheralOptionNotifyOnDisconnectionKey:[NSNumber numberWithBool:TRUE]}];
            
            NSLog(@"peripheral:%@",peripheral);
            
            
        }
    执行后会看到2015-12-19 17:32:07.753 AncsDemo[546:232404] retrivedArray:
    (
        "<CBPeripheral: 0x14f57d8f0, identifier = 7626B77E-5633-D09B-5C2A-0A022D4D61D8, name = ble_demo, state = disconnected>"
    )
    2015-12-19 17:32:07.753 AncsDemo[546:232404] peripheral:<CBPeripheral: 0x14f57d8f0, identifier = 7626B77E-5633-D09B-5C2A-0A022B1D61D7, name = ble_demo, state = connecting>
      

  2.   

    请问有关于ANCS的demo吗?