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

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

如图所示

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

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];
        }

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 174,650评论 25 709
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,301评论 4 61
  • 蓝牙简介 蓝牙( Bluetooth® ):是一种无线技术标准,可实现固定设备、移动设备和楼宇个人域网之间的短距离...
    Chefil阅读 2,105评论 2 19
  • 每年的十一长假不仅是出游的高峰期,也是婚宴喜宴的好日子。 今天是高中同学的大喜日子。在婚宴上遇见了好多老同学,感觉...
    姗姗Fiona阅读 277评论 1 0
  • 有言所谓情到深处情转薄,但我觉得情感原本就该如涓涓细流,动而不乱,缓而不断 不工作,如何证明还活着? 没有时间改变...
    24e2f6668318阅读 242评论 0 0