iOS CoreBluetooth - Peripheral connect to Central within range

霸气de小男生 提交于 2019-12-25 01:34:02

问题


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.

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

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.

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.


回答1:


In CoreBluetooth it is the central that makes the connection.

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.



来源:https://stackoverflow.com/questions/51994468/ios-corebluetooth-peripheral-connect-to-central-within-range

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!