在Swift应用程序中关闭蓝牙时如何显示警报?

编程入门 行业动态 更新时间:2024-10-26 14:29:51
本文介绍了在Swift应用程序中关闭蓝牙时如何显示警报?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这个问题可以重复,但是我尝试了很多代码,但是没有用。我已经读过

The question could be duplicated, but I have tried a lot of code and it wasn't work. I have read about

CBCentralManagerOptionShowPowerAlertKey

CBCentralManagerOptionShowPowerAlertKey

选项,并可能显示警报以将iPhone的设置蓝牙选项打开以打开应用程序,但我没有得到这个效果。

option and the possibility to show an alert to go settings bluetooth option into iPhone for turn on on the application, but I haven't get works this.

如果我设置了密钥为true时密钥不出现,并且当我将值更改为false时密钥不起作用...

If I set the key to true the key not appear, and when I change the value to false the key not works...

我在我的Swift应用程序中使用以下代码:

I'm using this code into my Swift application:

var bCentralManger: CBCentralManager! self.bCentralManger = CBCentralManager(delegate: self, queue: DispatchQueue.main, options: [CBCentralManagerOptionShowPowerAlertKey: true])

在iOS中使用此选项吗?我在设备上使用的是iOS 12。这个代码有人工作吗? 谢谢!

Works this option in iOS? I'm using iOS 12 on my device. Have anybody this code working? Thanks!

推荐答案

仅当 Settings 应用。如果仅从控制中心禁用蓝牙,则不会显示该对话框。从控制中心禁用蓝牙会断开所有连接的外围设备的连接,但不能完全关闭蓝牙硬件的电源。

The Bluetooth power alert is only shown if Bluetooth is turned off from the Settings app. If you simply disable Bluetooth from the control center, then the dialog is not shown. Disabling Bluetooth from the control center disconnects any connected peripherals but does not completely power off the Bluetooth hardware.

您可以显示自己的警报,以响应 .poweredOff 状态。不幸的是,在这种情况下,您无法直接将用户发送到蓝牙设置。

You can display your own alert in response to a .poweredOff state in the centralManagerDidUpdateState delegate method. Unfortunately you cannot send the user directly to the Bluetooth settings in this case.

您可以就此行为向Apple记录Radar,但我怀疑他们会回应系统正在按预期工作。

You could log a Radar with Apple regarding this behaviour, but I suspect that they will respond that the system is working as intended.

更多推荐

在Swift应用程序中关闭蓝牙时如何显示警报?

本文发布于:2023-11-27 20:36:42,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:蓝牙   警报   应用程序   Swift

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!