如果你要问,什么是蓝牙, BLE4.0,BLE5.0啥的, 请QQ私聊红包,语音一对一,温柔,包懂. 妹子优先.^_^
好吧,不逗了. 代码走起:
一: 导入苹果提供的 蓝牙框架
#import <CoreBluetooth/CoreBluetooth.h>
二:初始化: 1-2


三.centralManager 搜索 Peripheral 设备,连接设备,连接成功后, 3-4-5-6




四.Peripheral连接成功后:
#pragma mark CBPeripheralDelegate 🎥
#pragma mark -------------------------------------------
//连接成功后会,扫描发现 特征服务
-(void)peripheral:(CBPeripheral*)peripheral didDiscoverServices:(NSError*)error
//扫描特征值服务,有哪些特征值......
-(void)peripheral:(CBPeripheral*)peripheral didDiscoverCharacteristicsForService:(CBService*)service error:(NSError*)error
//当特征更新了,就会调用
- (void)peripheral:(CBPeripheral*)peripheral didUpdateValueForCharacteristic:(CBCharacteristic*)characteristic error:(nullableNSError*)error
以上就是蓝牙连接外设的整个代码过程.
一些其他配置:
app开启蓝牙权限: 7, info.plist添加如图

如果项目需要保持后台蓝牙连接: 8 -9 ,info.plist添加如图


最后如果有误,或者还有更多补充的欢迎留言,大家一起讨论,一起成长!!!!!!!! ^_^
网友评论