ios - BLE 设备不断连接/断开连接
<p><p>我正在使用我的应用程序连接 <code>BLE 设备</code> 并跟踪连接状态,如下所示</p>
<pre><code>//Called when device is connected
- (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral
{
;
if (peripheral.isConnected)
{
currentStatusLbl.text = ;
}
}
//Called if device disconnects
-(void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error
{
currentStatusLbl.text = ;
; //Connect again
}
//Device found, request connection
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
{
NSString *localName = ;
devieName.text = ;
if (localName && !)
{
;
self.activePeripheral = peripheral;
self.activePeripheral.delegate = self;
;
}
}
</code></pre>
<p>运行 <code>7.1.1</code> 的 <code>iPhone 5</code> 遇到的问题是标签上的状态不断在连接和断开之间切换。状态栏上的蓝牙图标确认了这一点(持续显示连接和断开状态)。我尝试打开/关闭设备(BLE 设备和手机的硬重置)。还打开/关闭蓝牙。但我仍然遇到这个问题。</p>
<p>我也遵循 <a href="https://stackoverflow.com/questions/21501208/ios-ble-peripherals-keep-disconnecting-immediately-after-discoverservices-is-cal" rel="noreferrer noopener nofollow">here in this question</a> 提供的建议但没有运气。</p>
<p>如果我做错了什么或者这是操作系统问题,有人可以告诉我吗?</p>
<p>谢谢。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>写[主动外设保留];在 didDisconnectPeripheral 的 if 条件内。
希望对你有帮助</p></p>
<p style="font-size: 20px;">关于ios - BLE 设备不断连接/断开连接,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/23909284/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/23909284/
</a>
</p>
页:
[1]