zoukankan      html  css  js  c++  java
  • ios中蓝牙自动连接出现硬件提示框的问题

    出现如图所示情况,这时候有两种方法可以处理,一种是让硬件部修改硬件配对,另一种是程序里面测试该提示框的对应特征值,不要调用该特征值就不会出现

    //2.扫描到Characteristics,特征回调

    -(void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error{

        

        for (CBCharacteristic *characteristic in service.characteristics)

        {

            _writePeripheral = peripheral;

          

            //截取设备uuid6

            NSString *UID2 =[UUIDSERVICE2 substringWithRange:NSMakeRange(4, 4)];

            //转化为大写

            NSString*UUIDString2 =[UID2 uppercaseString];

            

            //获取当前密码状态

            if ( [characteristic.UUID.UUIDString isEqualToString:UUIDString2]) {

                _readCharacteristic =characteristic;

                

                [peripheral setNotifyValue:YES forCharacteristic:characteristic];

                

            }

     

            

            //截取设备uuid6

            NSString *UID6 =[UUIDSERVICE6 substringWithRange:NSMakeRange(4, 4)];

            //转化为大写

            NSString*UUIDString6 =[UID6 uppercaseString];

            

            //截取设备uuid4

            NSString *UID4 =[UUIDSERVICE4 substringWithRange:NSMakeRange(4, 4)];

            //转化为大写

            NSString*UUIDString4 =[UID4 uppercaseString];

          //写入数据

            if ( [characteristic.UUID.UUIDString isEqualToString:UUIDString6]) {

                // 拿到特征,和外围设备进行交互   保存写的特征

                _writeDataCharacteristic = characteristic;

     

                [peripheral setNotifyValue:YES forCharacteristic:characteristic];

            }

            //获取当前状态

            if ( [characteristic.UUID.UUIDString isEqualToString:UUIDString4]) {

                _readCharacteristic =characteristic;

                

                [peripheral setNotifyValue:YES forCharacteristic:characteristic];

                

            }

            

     

            

            

        }

    }

     

    在这里不要调用多余的特征值和提示框显示的特征值,

       [peripheral readValueForCharacteristic:characteristic];这行代码要注意在特定的特征值里再调用,特征值外面别调用,不然问题就来了

  • 相关阅读:
    Gravatar注册
    global name 'validate_on_submit' is not defined错误
    TypeError: 'bool' object is not callable g.user.is_authenticated()
    no module named flask.ext.login
    No module named migrate.versioning
    Flask-WTF form doesn't have attribute 'validate_on_submit'问题
    can not import Flask错误
    跨站点请求伪造
    sqlserver插入时发生在“xxx”处关键发生错误
    python 爬虫实列
  • 原文地址:https://www.cnblogs.com/xiwanxiang190351/p/6229217.html
Copyright © 2011-2022 走看看