美文网首页iOS常用
iOS 去除系统提示打开蓝牙提示框

iOS 去除系统提示打开蓝牙提示框

作者: KingWorld | 来源:发表于2021-08-03 11:14 被阅读0次

    本人在开发中要用到蓝牙连接外设,但是蓝牙在没打开的情况下,系统每次都提示,我们只需检测蓝牙是否打开关闭,下面是解决办法希望可以帮助到遇到同样坑的码农!

    image

    这样写在蓝牙未打开时会有系统提示框:

     self.centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
    
    

    关闭代码:

    self.centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil options:nil];
    
    

    这样写就会关闭。

    options 参数讲解
    *
    *   @seealso        CBCentralManagerOptionShowPowerAlertKey  蓝牙系统为关闭状态,是否向用户显示警告对话框
    *   @seealso        CBCentralManagerOptionRestoreIdentifierKey
    *
    
    

    还有一个坑iOS 10以上跳转到蓝牙设置界面代码发生变化,以下为解决代码:

            NSURL *url = [NSURL URLWithString:@"App-Prefs:root=Bluetooth"];
            if ([[UIApplication sharedApplication]canOpenURL:url]) {
    
                [[UIApplication sharedApplication]openURL:url];
            }
    

    转载:iOS 去除系统提示打开蓝牙提示框

    相关文章

      网友评论

        本文标题:iOS 去除系统提示打开蓝牙提示框

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