美文网首页iOS成长路线iOS Devgood
关闭系统自带蓝牙提示(打开蓝牙来允许”xxx”连接到配件)

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

作者: 策马鞭程 | 来源:发表于2016-08-30 09:44 被阅读3185次

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

如图所示

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

Paste_Image.png

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

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


Paste_Image.png

自定义提示,如下图所示

看图

:

设置代码如下:

 // 蓝牙未打开
        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];
        }

相关文章

网友评论

  • 06d2242f45e2:感谢楼主分享,我按照文章的方法修改,弹出了自定义的对话框,不过最后点击“设置”按钮的时候,没有链接到蓝牙开启页面,这是为什么?
    Jackie_123:@Golotus 现在好像跳转到设置界面都不行了,会被拒
    06d2242f45e2:@策马鞭程 是的,原因已查明了,现在只能跳转到系统"设置"界面,不能精确到功能了
    策马鞭程:@Golotus iOS10系统做了调整,无法跳转。

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

本文链接:https://www.haomeiwen.com/subject/cbyfettx.html