gpt4 book ai didi

ios - 核心蓝牙 :Disconnect peripheral Connection from application

转载 作者:可可西里 更新时间:2023-11-01 05:11:45 25 4
gpt4 key购买 nike

我的应用程序与外围设备的蓝牙通信有关。从发现到连接,每个功能都工作正常。在断开外围设备与应用程序的连接时,我编写了这样的代码

  -(void) disconnect
{
if (_selectedPeripheral != nil &&
_selectedPeripheral.state != CBPeripheralStateDisconnected)
{
NSLog(@"Peripheral disconnecting");
[_centralManager cancelPeripheralConnection:_selectedPeripheral];
_selectedPeripheral = nil;
}
}

当我单击按钮时,上述方法正在调用,应用程序显示外围设备已断开连接,当我退出应用程序并查看设置/蓝牙/时。外围设备显示已连接。如何在设备级别停止连接外围设备即在设置中。请帮助我找到正确的解决方案。

最佳答案

您无法保证与外围设备的系统级断开连接。

这是直接来自 CBCentralManager 文档的链接:

cancelPeripheralConnection:

Discussion

This method is nonblocking, and any CBPeripheral class commands that are still pending to peripheral may or may not complete. Because other apps may still have a connection to the peripheral, canceling a local connection does not guarantee that the underlying physical link is immediately disconnected. From the app’s perspective, however, the peripheral is considered disconnected, and the central manager object calls the centralManager:didDisconnectPeripheral:error: method of its delegate object.

根据我的经验,如果您是唯一使用外围设备的应用程序,物理链接会很快断开,但如果您可能不是 Apple 明确声明的那样,则其他应用程序可能会保持持久连接,这会导致物理连接链接不要断开连接,即使它向您说明它已断开连接。

关于ios - 核心蓝牙 :Disconnect peripheral Connection from application,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30212820/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com