-(void) disconnect { if (_selectedPeripheral != nil && _selectedPeripheral.state != CBperipheralstatedisconnected) { NSLog(@"Peripheral disconnecting"); [_centralManager cancelPeripheralConnection:_selectedPeripheral]; _selectedPeripheral = nil; } }
当我单击按钮时,上面的方法是调用和应用程序显示外围设备已断开连接,当我从应用程序中出来并查看设置/蓝牙/ .Peripheral正在显示已连接.如何停止连接外围设备级别,即在设置.请帮我解决问题.
解决方法
这是直接来自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明确指出的那样,其他应用程序可能会维持持久连接,这会导致物理链接不能尽管它已经向你说明它已经断开了.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。