Continuous connectivity of bluetooth peripheral - ios

After connecting with CBPeripheral, it displays services & characteristics of peripheral, after few minutes it disconnects the peripheral without any user interaction. I want the continuous connection with device until user disconnects it.
I have used the demo: Fullband
Any help will be appreciated regarding the continuous connectivity with CBPeripheral.

Related

Failed to retrieve services of a CBPeripheral after restart the peripheral

I have a problem while trying to reconnect with a paired peripheral, it connects but I can not find the services.
The steps are as follows.
Turn on the peripheral device and open app.
Find the peripheral after scan. OK
Connect to the peripheral. OK
Save peripheral id for future reconnection.
Find the services / Characteristics. OK
Now I disabled the bluetooth from IOS and turned it on again to test the reconnection.
Find the peripheral after scan. OK
Connect to the peripheral with saved id. OK
Find the services / Characteristics. OK
Now I closed the app and reopen to test again.
Find the peripheral after scan. OK
Connect to the peripheral with saved id. OK
Find the services / Characteristics. OK
Now turn off the peripheral and then turn on again.
Find the peripheral after scan. OK
Connect to the peripheral with saved id. OK
Find the services / Characteristics. DOES NOT WORK NEVER MORE.
After step 4 if i repeat steps 1,2 and 3 they will not find services, the problem is when I restart the peripheral.
I'm setting the self.manager.delegate=self and implementing CBCentralManagerDelegate and CBPeripheralDelegate correctly, and I'm using self.manager.retrievePeripherals (withIdentifiers: [UUID]) to connect to the paired peripheral.
Any idea? I will be very grateful.

BLE Device reconnect after powered off

When I powered off bluetooth device then didDisconnectPeripheral delegated is invoked.
When I power on the bluetooth device, which delegate function will be called?
After disconnecting, you should restart scanning (scanForPeripheralsWithServices) for reconnect to the device.
Here you have documentation to CBCentralManager.
In this link you have a step by step tutorial to handle BLE Connection in swift.
After you power on your BLE device in your app (if it is active) will ba called function
centralManager:didDiscoverPeripheral:advertisementData:RSSI:
link to Apple documentation
In didDisconnectPeripheral you can immediately call connectPeripheral:options to create a pending connection. Once the peripheral is powered on or comes back into range you will get a call to the didConnectPeripheral delegate method

Unable to reconnect after cancelling BLE peripheral connection iOS

In my project I was successful to connect to a Bluetooth LE peripheral and read CBCharacteristic value from that device. I am facing an issue. I need to disconnect the peripheral and reconnect the device again if user wishes.
I am using the following steps.
1. For Disconnecting:
I am calling
centralManager?.cancelPeripheralConnection(peripheral). This call is completed successfully calling delegate func centralManager(central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: NSError?)
2. To Reconnect: I start scanning for peripherals, as I did when the app launched centralManager!.scanForPeripheralsWithServices(nil, options: nil)
But this call never calls the delegate func centralManager(central: CBCentralManager, didDiscoverPeripheral peripheral: CBPeripheral, advertisementData: [String : AnyObject], RSSI: NSNumber) where I try to connect the BLE discovered peripheral.
My question is what is the best practice to disconnect a BLE peripheral and reconnect it again in iOS. Am I doing anything wrong?
Thats not the right way to re-connect to BLE.
Per Apple Documentation:
Reconnecting to Peripherals
Using the Core Bluetooth framework, there are three ways you can
reconnect to a peripheral. You can:
Retrieve a list of known peripherals—peripherals that you’ve discovered or connected to in the past—using the
retrievePeripheralsWithIdentifiers: method. If the peripheral you’re
looking for is in the list, try to connect to it. This reconnection
option is described in Retrieving a List of Known Peripherals.
Retrieve a list of peripheral devices that are currently connected to the system using the retrieveConnectedPeripheralsWithServices:
method. If the peripheral you’re looking for is in the list, connect
it locally to your app. This reconnection option is described in
Retrieving a List of Connected Peripherals.
Scan for and discover a peripheral using the
scanForPeripheralsWithServices:options: method. If you find it,
connect to it. These steps are described in Discovering Peripheral
Devices That Are Advertising and Connecting to a Peripheral Device
After You’ve Discovered It.

iOS CoreBluetooth and preventing other devices to connect to your peripheral

I am creating a core bluetooth application and connecting to a peripheral device, is there a way for the peripheral to reject which centrals may connect to it? What if a random person scanned and found my peripheral devices broadcasted UUID and then broadcasted that UUID and tried to connect to it, how would I prevent this?
No, the iOS peripheral cannot prohibit centrals from connecting to it. However it has some tricks to disable the connection. When a dynamic characteristic is read:
return an error instead of the value of the characteristic,
don't respond to the request. This will cause the connection to stall and then break up after about 30 seconds.
Think of the advertisement as a real advertisement in the media. As many can see it as want. This is the same for iBeacons. You shouldn't rely any security on being hidden. (Wifi SSID broadcasting can be turned off but if your hotspot is not encrypted and authenticated, people with find you.)

how to restore Broadcom WICED Bluetooth LE communication after connection attempt to dead peripheral

After attempt to connect to a Bluetooth address for a peripheral that just powered off (battery died), central can no longer connect to any other powered-up peripherals. (This would occur if central scans for and detects peripheral, but peripheral then is powered off before central connects to it.)
Peripheral with Bluetooth address '000000000001' is powered on, and peripheral '000000000002' is powered off.
Central connects to P1 okay and gets notifications. Then disconnects.
Central tries to connect to peripheral '000000000002'.
Central disconnects.
Central tries to connect to '000000000001' again, but does not even get the connUp callback.
Why can't central re-connect with peripheral '000000000001' ?
Solution is to scan for the peripheral first, and only attempt connection if peripheral is NOT dead.

Resources