iOS CoreBluetooth-外设连接到范围内的Central [英] iOS CoreBluetooth - Peripheral connect to Central within range

查看:143
本文介绍了iOS CoreBluetooth-外设连接到范围内的Central的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个与Objective-C一起运行的基本BLE应用程序。我正在使用PeripheralManager,并将我的iPhone8作为具有功能的外设运行,添加了特性。

I have a basic BLE App that I am running with Objective-C. I am using PeripheralManager and running my iPhone8 as a peripheral with serivces, characteristics added.

我想做的是连接到我通过设备ID知道的中央设备或它何时在范围内。

What I would like to do is connect to a central device that I know by Device ID or when it comes within range.

我已经编写了一个适用于Android的BLE应用,现在可以做到这一点。我要做的就是在连接onConnectionStateChange()时触发device.connectGatt()。这是在BluetoothGattServerCallback()eventHandler中。

I have written a BLE App for Android that does this now. All I have to do is trigger the device.connectGatt() when onConnectionStateChange() is connected. This is in the BluetoothGattServerCallback() eventHandler.

在iOS中对此等效吗?请记住,这是处于连接状态,而不是中央服务器已订阅服务时。在Android上的BluetoothGatt中这似乎很明显,但在iOS PeriphalManager中看不到任何明显的东西。

What is the equivant for this in iOS? Keep in mind I that this is at connected state, not when the central has subscribed for services. This seems obvious in BluetoothGatt on Android but not see anything obvious in iOS PeriphalManager.

有人做过类似的事情吗?

Anyone done anything similar? Seems to be a basic question, please help.

推荐答案

在CoreBluetooth中,建立连接的中心。

In CoreBluetooth it is the central that makes the connection.

如果您知道外围设备的特定于设备的标识符(即您之前已在此中央设备上发现它),则可以尝试检索 CBPeripheral 实例,然后发出 connect 。当设备进入范围时,这将完成。如果您允许后台模式,则当您的应用程序处于后台时,可以完成此连接。

If you know the device-specific identifier for a peripheral (ie, you have previously discovered it on this central device) then you can attempt to retrieve a CBPeripheral instance from the central and then issue a connect. This will complete when the device comes into range. If you allow background mode then this connect can be completed when your app is in the background.

这篇关于iOS CoreBluetooth-外设连接到范围内的Central的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆