大佬教程收集整理的这篇文章主要介绍了ios – 连接两个BLE外设的流程是什么样的?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我想连接两个CBPeripherals并将数据写入它们.根据我的阅读,我认为在连接第二个设备之前,我必须断开当前的外围设备.好吧,假设我要将一个命令写入其中一个外设,然后我想将另一个命令写入另一个外设,我是否必须断开与当前外设的连接?如果我断开连接到另一个,前一个命令是否仍然有效? iOS上最好的做法是什么?
[[RKCentralManager sharedManager] scanForPeripheralsWithservices:nil options:@{CBCentralManagerScanOptionAllowDuplicatesKey:@NO} onupdated:^(RKPeripheral *peripheral) { //first of all u should start a scan [[RKCentralManager sharedManager] connectPeripheral: peripheral options:nil onFinished:^(RKPeripheral * connectedperipheral,NSError *error) { //after u can connect to Peripheral immediately [connectedperipheral discoverservices:nil onFinish:^(NSError *error) { // services - a collection of data and associated behaviors for accomplishing a function or feature of a device [connectedperipheral discovercharacteristics:nil forservice: [connectedperipheral.services lastObject] onFinish:^(CBservice *service,NSError *error) { //after u should take a characteristic - Represents a service's characteristic CBCharacteristic * characteristic = service.characteristics[0]; //and at last u can write value in characteristic in which you are going to write down something NSData * data = [NSData dataWithHexString: newString]; CBCharacteristicWriteType @R_874_4763@BCharacteristicWriteWithoutResponse; [connectedperipheral writeValue:data forCharacteristic:characteristic type:type onFinish:nil]; }]; }]; }]; }];
为蓝牙设备发送消息的近似方案,不是必须对@L_616_11@进行投资,它们可以在动作上分发.
您不应该担心连接和发送数据
对于多个设备,因为它适用于CBCentralManager,如果你正确使用它.
CBCentralManager对象用于管理已发现或连接的远程外围设备(由CBPeripheral对象表示),包括扫描,发现和连接到广告外围设备.
您可以立即连接某些设备并向其发送消息,一切正常.
如果您有疑问,请尽量回答.
这是一个很好的例子,你可以看到它的工作原理:https://github.com/ruiking/ble
以上是大佬教程为你收集整理的ios – 连接两个BLE外设的流程是什么样的?全部内容,希望文章能够帮你解决ios – 连接两个BLE外设的流程是什么样的?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。