在Swift应用程序中关闭蓝牙时如何显示警报? [英] How to show an alert when turn off bluetooth in Swift app?

查看:201
本文介绍了在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.

您可以显示自己的警报,以响应 centralManagerDidUpdateState 委托方法中的> .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应用程序中关闭蓝牙时如何显示警报?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆