- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
所以有一种方法可以通过centralManagerDidUpdateState()
来监控CBCentralManager
的状态变化。但是是否有类似的方法调用来监控CBPeripheral
的状态变化?我在 CoreBluetooth
库中找不到任何公开的内容,并且我想在 CBPeripheralState
更改时调用一个函数。
现在我只有一个检查外围设备状态的 switch 语句,但它总是会返回连接或断开连接。我将如何到达连接/断开连接的情况?我尝试将 switch 语句放在代码的各个部分,从 bleInit()
方法到 startScanning()、connectToPeripheral()
等
switch(peripheral.state){
case .disconnected:
print("disconnected")
case .connecting:
print("connecting")
case .connected:
print("connected")
case .disconnecting:
print("disconnecting")
default: break
}
最佳答案
连接和断开状态是过渡状态。您的连接只会在很短的时间内处于这些状态;这就是为什么你永远不会看到那些状态。
如果您的应用充当中心,则通过 CBCentralManager
的 didConnect
和 didDisconnectPeripheral
方法通知外围连接状态。
关于ios - 监控 CBPeripheral 状态变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43239687/
我调用方法 ( void)connectPeripheral:(CBPeripheral *)peripheral options:(nullable NSDictionary *)options;
我正在从数据库中检索数据记录,然后将每条记录写入 BLE 设备的 CBCharacteristic。编写实现, for service in self.connectedPeripheral!.ser
我有一个蓝牙设备。与它连接后,我想在后台重新连接它。问题是我不知道如何在用户强制退出应用程序后重新连接到设备(即使在新应用程序启动后) 我有:广告数据中没有服务的蓝牙设备。 因为它没有广告数据,所以我
当使用 CoreBluetooth 框架访问低功耗蓝牙设备时, CBCentralManager 返回 CBPeripheral 用于外设。 外围设备上有多个服务可用,我想将处理不同服务的特征值更新的
我正在开发一个应用程序,它可以多次连接和断开连接到不同的低功耗蓝牙外围设备。在互联网上进行了大量研究后,我没有找到一种方法来存储已经发现的服务和特征,以便我可以更快地重新连接。目前,每次重新连接后我都
我遇到了有关 CoreBluetooth 框架的问题。 例如,我有两台设备,每台设备都执行广告和扫描。因此,我在每个上都使用了 CBCentralManager 和 CBPeripheralManag
我在使用已更新服务的 CBPeripheral 时遇到一些问题:我的物理设备有一个更新广告服务的按钮,但我的应用程序仍在委托(delegate)方法 didDiscoverServices 中读取旧服
我们的应用程序通过CoreBluetooth连接到Bluetooth LE设备。 在iOS 8和9上,一切正常。在iOS 10上,我们遇到了超时错误(Error Domain=CBErrorDomai
有没有办法检查 CBPeripheral 是否实际上仍然可以连接? 我使用CBCentralManager扫描外围设备,它会在didDiscover外围设备:中返回我的外围设备。 如果我关闭并再次打开
我们的应用程序与使用 ANCS 的配对蓝牙外围设备配合使用,这就是为什么我很早就研究了全新的隐私设置“共享系统通知”,以使我们的应用程序为 iOS13 做好准备......但是有一个问题,CBPeri
我正在开发一个测试 BTLE 应用程序。用户可以选择启动中央或外设模式。如果 2 个设备都处于事件状态并且在范围内,它们会立即检测、连接并传递数据,但是...... 如果设备 1 以中央模式启动然后置
我只希望受信任的设备连接到我的外围设备。而且我不希望任何人能够发现我的外围设备的服务和特征。因此,在连接到外围设备之前,我想显示一个带有 pin 码的警报。有可能做到吗?最简单的方法是什么? 我找不到
我想连接到蓝牙硬件,但我无法收到通知,当值更新时,读取读取,这是我的代码: func peripheral(peripheral: CBPeripheral, didDiscoverCharacter
在我的应用程序中,我需要将数据写入外设的可写特性。我能够通过扫描外围设备、检测并连接到外围设备、发现服务、发现特征然后最后写入目标特征的过程来做到这一点。 完成所有这些后,我保留了我感兴趣的 CBPh
我有一个类是 CBPeripheral 的子类。这样我就可以向 CBPeripheral 添加其他属性。 在 centralManager 委托(delegate)方法 didDiscoverPeri
我正在使用 CoreBluetooth 框架实现 CentralManager,以便提取外围设备提供的值。 我首先查找具有特定 UUID(“52486FA8-FF0B-4A91-A344-D642D0
我最近创建了一个在 iOS 上使用 CoreBluetooth 连接到热敏打印机的应用程序。除了一件事,一切都很好。我可以看到 20 多个蓝牙设备,但只有一个是热敏打印机。有没有办法让我在连接之前知道
所以有一种方法可以通过centralManagerDidUpdateState() 来监控CBCentralManager 的状态变化。但是是否有类似的方法调用来监控CBPeripheral的状态变化
我正在开发一款与蓝牙 LE 外围设备通信的应用程序。我目前正在测试的外围设备是 these 之一。 .有趣的是,有时当我发现它时,我会得到它的专有名称“SimpleBLEPeripheral”,有时我
我正在编写一个应用程序,允许我通过 BLE 将图像发送到其他人的应用程序。 为了正确测试它,我需要能够连接到设备,但我扫描的外围设备总是断开连接,并且值为零。我不确定我这样做是否正确。我一直在阅读指南
我是一名优秀的程序员,十分优秀!