美文网首页iOS Developer
蓝牙基本要会的方法总结以及用到block回调

蓝牙基本要会的方法总结以及用到block回调

作者: 邵琼 | 来源:发表于2016-11-16 20:57 被阅读154次

一:外围设备

1.蓝牙中用到的方法:如下:一定要掌握

CBPerpheral(外围设备): 属性有:state  name ,services;  方法有:readRSSI discoverServices  discoverCharacteristic   writeValueforCharacteristic(写入数据)  setNotifyValueforCharacteristic(读取数据)  readValueForDescriptor    writeValueForDescriptor  

2.CBPerpheralDelegate代理方法有:didDiscoverServices   didUpdateValueForCharateristic  等等,都是did.. 也即是一些回调方法

二:中央设备

1.CBCentralManager(中央设备,也就是手机)  -scanForPeriphralsWithServices                    -connnectPeriphral 

2.代理方法: didUpdateState   didConnnectPeripheral

三:block回调:

1.在要向外传值页面设置:

.h

@property (nonatomic, copy) void(^passValueBlock)(NSString *str);

这里,void(^)(NSString *)为类型  , passValueBlock为变量

.m

if (_passValueBlock != nil) {

//_passValueBlock为block型的变量

_passValueBlock(self.backTextFeild.text);

}

2.需要接受的页面:

BViewController *BVC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"bVC"]; // storyBorad创建的页面不能直接用alloc init.

[BVC setPassValueBlock:^(NSString *str) {

[self.nextBtn setTitle:str forState:UIControlStateNormal];

}];

相关文章

网友评论

    本文标题:蓝牙基本要会的方法总结以及用到block回调

    本文链接:https://www.haomeiwen.com/subject/mmwrpttx.html