CoreBluetooth使用 (服务端中心设备)
2015-08-21 11:02
543 查看
自己写了一个Demo 下载地址:http://download.csdn.net/detail/i_k_o_x_s/9031359
CBCentralManager类
//初始化的时候 调用代理方法 返回当前设备的蓝牙状态
- (void)centralManagerDidUpdateState:(CBCentralManager *)central
//开始扫描周边蓝牙设备
停止扫描
serviceUUIDS options 为nil 不指定搜索条件
- (void)scanForPeripheralsWithServices:(NSArray *)serviceUUIDs options:(NSDictionary
*)options;
- (void)stopScan;
// 当设备搜索到周边蓝牙设备的时候 回调代理方法
peripheral 设备 advertisementData 设备广告发出来的信息 RSSI 设备强度
-(void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral
*)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
// 连接指定蓝牙设备
- (void)connectPeripheral:(CBPeripheral *)peripheral options:(NSDictionary *)options;
//取消连接指定蓝牙设备
- (void)cancelPeripheralConnection:(CBPeripheral *)peripheral;
// 和周边蓝牙设备连接成功 回调代理方法
-(void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral
*)peripheral
{
//设置代理
peripheral.delegate =self;
[peripheral discoverServices:nil];
}
// 和周边蓝牙设备连接失败 回调代理方法
-(void)centralManager:(CBCentralManager *)central didFailToConnectPeripheral:(CBPeripheral
*)peripheral error:(NSError *)error
CBPeripheral类
CBPeripheralDelegate 代理
// 外部设备寻找到服务后 回调代理方法
-(void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error{
// 外围设备查找指定服务中的特征 服务
- (void)discoverCharacteristics:(NSArray *)characteristicUUIDs forService:(CBService
*)service;
//外围设备寻找到特征后 回调代理方法
-(void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService
*)service error:(NSError *)error{
// 设置激活通知 到指定特征
- (void)setNotifyValue:(BOOL)enabled forCharacteristic:(CBCharacteristic *)characteristic;
//特征值被更新后 回调代理回调
-(void)peripheral:(CBPeripheral *)peripheral didUpdateNotificationStateForCharacteristic:(CBCharacteristic
*)characteristic error:(NSError *)error{
// 订阅特征 更新数据 回调代理方法
characteristic.value 为特征发过来的数据
-(void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic
*)characteristic error:(NSError *)error
//客户端 CBPeripheralManager类 调用这个方法
- (BOOL)updateValue:(NSData *)value forCharacteristic:(CBMutableCharacteristic *)characteristic
onSubscribedCentrals:(NSArray *)centrals;
//写入数据到指定特征 客户端会接收回调代理方法
- (void)writeValue:(NSData *)data forCharacteristic:(CBCharacteristic *)characteristic
type:(CBCharacteristicWriteType)type;
//客户端 CBPeripheralManager类 调用这个方法
-(void
b712
)peripheralManager:(CBPeripheralManager *)peripheral
didReceiveWriteRequests:(NSArray *)requests{
//成功写入后回调的代理方法
- (void)peripheral:(CBPeripheral *)peripheral didWriteValueForCharacteristic:(CBCharacteristic
*)characteristic error:(NSError *)error
CBCentralManager类
//初始化的时候 调用代理方法 返回当前设备的蓝牙状态
- (void)centralManagerDidUpdateState:(CBCentralManager *)central
//开始扫描周边蓝牙设备
停止扫描
serviceUUIDS options 为nil 不指定搜索条件
- (void)scanForPeripheralsWithServices:(NSArray *)serviceUUIDs options:(NSDictionary
*)options;
- (void)stopScan;
// 当设备搜索到周边蓝牙设备的时候 回调代理方法
peripheral 设备 advertisementData 设备广告发出来的信息 RSSI 设备强度
-(void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral
*)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
// 连接指定蓝牙设备
- (void)connectPeripheral:(CBPeripheral *)peripheral options:(NSDictionary *)options;
//取消连接指定蓝牙设备
- (void)cancelPeripheralConnection:(CBPeripheral *)peripheral;
// 和周边蓝牙设备连接成功 回调代理方法
-(void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral
*)peripheral
{
//设置代理
peripheral.delegate =self;
[peripheral discoverServices:nil];
}
// 和周边蓝牙设备连接失败 回调代理方法
-(void)centralManager:(CBCentralManager *)central didFailToConnectPeripheral:(CBPeripheral
*)peripheral error:(NSError *)error
CBPeripheral类
CBPeripheralDelegate 代理
// 外部设备寻找到服务后 回调代理方法
-(void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error{
// 外围设备查找指定服务中的特征 服务
- (void)discoverCharacteristics:(NSArray *)characteristicUUIDs forService:(CBService
*)service;
//外围设备寻找到特征后 回调代理方法
-(void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService
*)service error:(NSError *)error{
// 设置激活通知 到指定特征
- (void)setNotifyValue:(BOOL)enabled forCharacteristic:(CBCharacteristic *)characteristic;
//特征值被更新后 回调代理回调
-(void)peripheral:(CBPeripheral *)peripheral didUpdateNotificationStateForCharacteristic:(CBCharacteristic
*)characteristic error:(NSError *)error{
// 订阅特征 更新数据 回调代理方法
characteristic.value 为特征发过来的数据
-(void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic
*)characteristic error:(NSError *)error
//客户端 CBPeripheralManager类 调用这个方法
- (BOOL)updateValue:(NSData *)value forCharacteristic:(CBMutableCharacteristic *)characteristic
onSubscribedCentrals:(NSArray *)centrals;
//写入数据到指定特征 客户端会接收回调代理方法
- (void)writeValue:(NSData *)data forCharacteristic:(CBCharacteristic *)characteristic
type:(CBCharacteristicWriteType)type;
//客户端 CBPeripheralManager类 调用这个方法
-(void
b712
)peripheralManager:(CBPeripheralManager *)peripheral
didReceiveWriteRequests:(NSArray *)requests{
//成功写入后回调的代理方法
- (void)peripheral:(CBPeripheral *)peripheral didWriteValueForCharacteristic:(CBCharacteristic
*)characteristic error:(NSError *)error
相关文章推荐
- Xcode强大的多视图立体分层显示View UI Herarchy
- Hibernate SQL优化技巧dynamic-insert="true" dynamic-update="true"
- Jsp重定向(response.sendRedirect())和转发(request.getRequestDispatcher().forward(request,r)的区别
- Errors occurred during the build. Errors running builder 'DeploymentBuilder' on project '项目名'
- 在Android Studio中进行单元测试和UI测试
- Uiautomator Viewer中文显示乱码问题
- The requested URL /get_data.xml was not found on this server.
- spoj 375 QTREE - Query on a tree 树链剖分 LCT 动态树
- UIDeviceOrientation和UIInterfaceOrientation中left、right的含义
- Pop Sequence (25)--栈模拟经典
- The type java.util.Map$Entry cannot be resolved. It is indirectly referenced from required .class
- [LeetCode#52]N-Queens II
- Android开源资料大集合_架构&UI
- apue源码运行配置
- iOS UIViewController 和 nib 相关的3个方法
- Java之String,StringBuffer,StringBuilder类
- JAVA-QUEUE类图
- NGUI小细节 生成与点击事件
- UVA 540 Team Queue
- iOS中使用storyboard实现页面跳转,Segue详解及简单的数据传递