【问题标题】:BLE device keeps getting connected/disconnectedBLE 设备不断连接/断开连接
【发布时间】:2014-07-17 12:55:56
【问题描述】:

我正在使用我的应用程序与BLE device 连接并跟踪连接状态,如下所示

//Called when device is connected
- (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral
{
    [self.activePeripheral discoverServices:nil];
    if (peripheral.isConnected)
    {
        currentStatusLbl.text = [NSString stringWithFormat:@"Connected"];
    }
}

//Called if device disconnects
-(void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error
{
    currentStatusLbl.text = [NSString stringWithFormat:@"Disconnected"];
    [self.centralManager connectPeripheral:peripheral options:nil]; //Connect again
}

//Device found, request connection
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
{
     NSString *localName = [advertisementData objectForKey:CBAdvertisementDataLocalNameKey];
     devieName.text = [localName stringByAppendingString:@" Found"];
     if (localName && ![localName isEqual:@""])
     {
         [self.centralManager stopScan];
         self.activePeripheral = peripheral;
         self.activePeripheral.delegate = self;
         [self.centralManager connectPeripheral:peripheral options:nil];
     }
}

运行7.1.1iPhone 5 面临的问题是标签上的状态不断在连接和断开之间切换。状态栏上的蓝牙图标确认了这一点(继续显示连接和断开状态)。我尝试打开/关闭设备(BLE 设备和手机的硬重置)。还打开/关闭蓝牙。但我仍然遇到这个问题。

我也遵循here in this question 提供的建议,但没有运气。

如果我做错了什么或者这是操作系统问题,有人可以告诉我吗?

谢谢。

【问题讨论】:

    标签: ios ios7 ios6 bluetooth-lowenergy core-bluetooth


    【解决方案1】:

    写 [activePeripheral 保留];在 didDiscoverPeripheral 的 if 条件中。 希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-18
      • 1970-01-01
      • 1970-01-01
      • 2016-10-05
      • 2016-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多