zoukankan      html  css  js  c++  java
  • 蓝牙开发笔记

    //把数据写到Characteristic中
    //写数据
    -(void)writeCharacteristic:(CBPeripheral *)peripheral
                characteristic:(CBCharacteristic *)characteristic
                         value:(NSData *)value{
        //打印出 characteristic 的权限,可以看到有很多种,这是一个NS_OPTIONS,就是可以同时用于好几个值,常见的有read,write,notify,indicate,知知道这几个基本就够用了,前连个是读写权限,后两个都是通知,两种不同的通知方式。
        /*
         typedef NS_OPTIONS(NSUInteger, CBCharacteristicProperties) {
         CBCharacteristicPropertyBroadcast                                                = 0x01,
         CBCharacteristicPropertyRead                                                    = 0x02,
         CBCharacteristicPropertyWriteWithoutResponse                                    = 0x04,
         CBCharacteristicPropertyWrite                                                    = 0x08,
         CBCharacteristicPropertyNotify                                                    = 0x10,
         CBCharacteristicPropertyIndicate                                                = 0x20,
         CBCharacteristicPropertyAuthenticatedSignedWrites                                = 0x40,
         CBCharacteristicPropertyExtendedProperties                                        = 0x80,
         CBCharacteristicPropertyNotifyEncryptionRequired NS_ENUM_AVAILABLE(NA, 6_0)        = 0x100,
         CBCharacteristicPropertyIndicateEncryptionRequired NS_ENUM_AVAILABLE(NA, 6_0)    = 0x200
         };
         */
        [self writeTolog:[NSString stringWithFormat:@"%lu", (unsigned long)characteristic.properties]];
        //只有 characteristic.properties 有write的权限才可以写
        if(characteristic.properties & CBCharacteristicPropertyWrite){
            /*
             最好一个type参数可以为CBCharacteristicWriteWithResponse或type:CBCharacteristicWriteWithResponse,区别是是否会有反馈
             */
            [peripheral writeValue:value forCharacteristic:characteristic type:CBCharacteristicWriteWithResponse];
        }else{
            NSLog(@"该字段不可写!");
        }
    }

    【链接】LightBlue基础使用教程
    http://www.jianshu.com/p/2bfde2ba8a99

    【链接】iOS蓝牙入门
    http://www.jianshu.com/p/ae8c44b166d7

    【链接】『CoreBluetooth』1.初识
    http://www.saitjr.com/ios/core-bluetooth-overview.html

     //1. 创建中心设备管理者,并且设置代理
     //初始化方式一:,不会提示出现"打开蓝牙允许'xxxx'连接都配件"的系统提示
       _myCentralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil options:nil];
       //初始化方式二
       _myCentralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
  • 相关阅读:
    Oracle、Db2、SqlServer、MySQL 数据库插入当前系统时间
    Mybatis---在控制台打印sql语句
    多线程实现的四种方法
    Restful架构
    maven中的pom配置文件一——spring,mybatis,oracle,jstl,json,文件上传
    spring mvc配置
    spring的事务
    cglib动态代理
    jdk动态代理
    spring总结————AOP面向切面总结
  • 原文地址:https://www.cnblogs.com/gaozhang12345/p/6182959.html
Copyright © 2011-2022 走看看