ios - BLE 设备不断连接/断开连接

标签 ios ios7 ios6 bluetooth-lowenergy core-bluetooth

我正在使用我的应用程序连接一个BLE 设备 并跟踪连接状态如下

//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但没有运气。

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

谢谢。

最佳答案

写[active Peripheral retain];在 didDisconnectPeripheral 的 if 条件内。 希望对你有帮助

关于ios - BLE 设备不断连接/断开连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23909284/

相关文章:

ios - 使用ErrorReauthorizedFailedReasonUserCancelled调用reauthorizeWithPublishPermissions处理程序

objective-c - iOS 6 通讯录清空 kABPersonPhoneProperty

cocoa - 当警报 View 关闭时,右侧导航栏按钮会移动

xcode - Xcode 如何自动从其父节点中删除 skspritenode

android - 如何在屏幕之间共享 React Native 组件

ios - 如何存储任意时间

ios7 - ios 7 MDM 服务器

ios6 - 改变 AVCaptureVideoPreviewLayer 方向的问题

android - 行高在 iPhone 和 iPad 上的显示方式与其他设备不同

ios - 不使用 OCMClassMock 调用方法