ios - 同时连接多个 BLE 设备 iOS
<p><p>我正在尝试扫描附近所有可用的 BLE 设备并与每个设备建立连接,以便我可以继续获取 RSSI 值。</p>
<p>这是我的代码:</p>
<pre><code>- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral
advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI {
NSLog(@"Received peripheral : \n%@", peripheral);
myPeripheral=peripheral;
NSLog(@"RSSI value:%@",RSSI);
;
peripheral.delegate=self;
}
-(void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral{
//NSLog(@"Peripheral Connected");
NSLog(@"%@ connected",peripheral.identifier);
}
</code></pre>
<p>谁能指导我如何建立与多个外围设备的连接?
谢谢</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>你可以这样做:</p>
<p><strong>第 1 步:</strong>停止扫描。这有助于加快连接速度。</p>
<pre><code>;
</code></pre>
<p><strong>第 2 步:</strong>扫描外围设备。</p>
<pre><code>;
</code></pre>
<p><strong>第 3 步:</strong>将所有发现的外设保存在委托(delegate)回调方法下方。</p>
<pre><code>centralManager:didDiscoverPeripheral:advertisementData:RSSI:
</code></pre>
<p><strong>步骤 2.1:</strong> 我称之为 2.1,因为这将在步骤 2 之后立即执行。使用 GCD,在延迟 2-5 秒后调度线程(用户 <code>dispatch_after</code>) 并循环保存的 Per 并调用 <code>connectPeripheral:options:</code> 方法来连接它们。</p></p>
<p style="font-size: 20px;">关于ios - 同时连接多个 BLE 设备 iOS,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/32708546/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/32708546/
</a>
</p>
页:
[1]