关闭系统自带蓝牙提示(打开蓝牙来允许”xxx”连接到配件)

需求是要自定义提示,系统自带的容易点击到<好>,而没有跳转蓝牙界面.

关闭系统自带蓝牙提示(打开蓝牙来允许”xxx”连接到配件)_第1张图片
如图所示

在非后台模式,添加一个值即可

关闭系统自带蓝牙提示(打开蓝牙来允许”xxx”连接到配件)_第2张图片
Paste_Image.png

CBCentralManagerOptionShowPowerAlertKey布尔值,表示的是在central manager初始化时,如果当前蓝牙没打开,是否弹出alert框。

上面的布尔值修改是无效的.


关闭系统自带蓝牙提示(打开蓝牙来允许”xxx”连接到配件)_第3张图片
Paste_Image.png

自定义提示,如下图所示

关闭系统自带蓝牙提示(打开蓝牙来允许”xxx”连接到配件)_第4张图片
看图

:

设置代码如下:

 // 蓝牙未打开
        if (central.state == CBCentralManagerStatePoweredOff) {
            UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"打开蓝牙来连接到配件" preferredStyle:(UIAlertControllerStyleAlert)];
            
            // 是否跳转到蓝牙界面
            UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"设置" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=Bluetooth"]];
            }];
            // 创建按钮
            // 注意取消按钮只能添加一个
            UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleCancel) handler:nil];
            
            // 添加按钮 将按钮添加到UIAlertController对象上
            [alertController addAction:cancelAction];
            [alertController addAction:okAction];
            
            // 将UIAlertController模态出来 相当于UIAlertView show 的方法
            [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:alertController animated:YES completion:nil];
        }

你可能感兴趣的:(关闭系统自带蓝牙提示(打开蓝牙来允许”xxx”连接到配件))