ios蓝牙4.0开发附demo

4 篇文章 0 订阅

参考:http://www.cocoachina.com/ios/20170824/20369.html

①蓝牙常见名称和缩写

  • MFI ======= make for ipad ,iphone, itouch 专们为苹果设备制作的设备

  • BLE ==== buletouch low energy,蓝牙4.0设备因为低耗电,所以也叫做BLE

  • peripheral,central == 外设和中心,发起连接的时central,被连接的设备为perilheral

  • service and characteristic === 服务和特征 每个设备会提供服务和特征,类似于服务端的api,但是机构不同。每个外设会有很多服务,每个服务中包含很多字段,这些字段的权限一般分为 读read,写write,通知notiy几种,就是我们连接设备后具体需要操作的内容。

  • Description 每个characteristic可以对应一个或多个Description用户描述characteristic的信息或属性

  • MFI === 开发使用ExternalAccessory 框架

  • 4.0 BLE === 开发使用CoreBluetooth 框架

     

     

    CoreBluetooth框架的核心其实是两个东西,peripheral和central, 可以理解成外设和中心

     

     

    ②蓝牙开发流程

    1. 建立中心管理者

    2. 扫描外设(discover)

    3. 连接外设(connect)

    4. 扫描外设中的服务和特征(discover)

        - 4.1 获取外设的services

        - 4.2 获取外设的Characteristics,获取Characteristics的值,获取Characteristics的Descriptor和Descriptor的值

    5. 与外设做数据交互(explore and interact)

    6. 订阅Characteristic的通知

    7. 断开连接(disconnect)

    ③蓝牙和版本的使用限制

    • 蓝牙2.0 === 越狱设备

    • 蓝牙4.0 === iOS 6 以上

    • MFI认证设备(Make For ipod/ipad/iphone) === 无限制

       

       

      ④写数据时要注意CBCharacteristicWriteWithoutResponse(写无回复)和

      CBCharacteristicWriteWithResponse(写有回复)的区别

      characteristic 属性 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 }; */ NSLog(@"%@",characteristic); // 打印结果为 <CBCharacteristic: 0x1702a2a00, UUID = FFF6, properties = 0x16, value = (null), notifying = NO> // 我的结果 为 0x16 (0x08 & 0x16)结果不成立, (0x04 & 0x16)结果成立,那写入类型就是 CBCharacteristicPropertyWriteWithoutResponse }

      在使用蓝牙的过程中,如果是iOS10及以上机型需要在info.plist文件中添加NSBluetoothPeripheralUsageDescription描述字段,向用户声明使用蓝牙的意图

       

       

      demo地址  https://download.csdn.net/download/haoxuhong/10290004

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值