蓝牙初探

一  concept :

1.Bluetooth Communication

central and peripheral devices

client                 server

central              peripheral

2. peripheral advertising  and  a central  scaning and listen

3.Peripherals  contain many services , a service  made up of characteristics or included services 

4. local centrals and Remote Peripherals 

CBCentralManager



A Local Peripheral’s Data Are Represented by CBMutableService and CBMutableCharacteristic Objects


二 怎么样 实现大多数蓝牙技术任务类型(来自central side)

  • Start up a central manager object
  • Discover and connect to peripheral devices that are advertising
  • Explore the data on a peripheral device after you’ve connected to it
  • Send read and write requests to a characteristic value of a peripheral’s service
  • Subscribe to a characteristic’s value to be notified when it is updated

Starting Up a Central Manager

myCentralManager =[ [CBcentralManager alloc] initWithDelegate: self queue:nil option:nil];

实现方法  centralManagerDidUpdateState:  检测是否支持蓝牙

Discovering Peripheral Devices That Are Advertising

    

 [myCentralManager scanForPeripheralsWithServices:nil options:nil];

如果发现了周围service回调方法:

centralManager:didDiscoverPeripheral:advertisementData:RSSI:


[myCentralManager stopScan];//停止扫


Connecting to a Peripheral Device After You’ve Discovered It


[myCentralManager connectPeripheral:peripheral options:nil];


链接成功会回调


centralManager:didConnectPeripheral:



建立链接之后


Discovering the Services of a Peripheral That You’re Connected To

[peripheral discoverServices:nil];


发现之后也会有相应的回调,然后去  

Discovering the Characteristics of a Service


当发现特征之后,也会有相应的回调:

peripheral:didDiscoverCharacteristicsForService:error:

然后读获取到的特征的值:

readValueForCharacteristic:


然后也会有回调:

peripheral:didUpdateValueForCharacteristic:error:


Subscribing to a Characteristic’s Value

[peripheral setNotifyValue:YES forCharacteristic:interestingCharacteristic];


只要有操作,基本就有相应的回调。








  



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值