iOS 6 - Bluetooth LE disconnect
Asked Answered
S

2

8

Ok what the heck is up with iOS6 and how it handles Bluetooth LE disconnections? Before the device would disconnect immediately but now, for some strange reason, the device waits to disconnect for about 30-60 seconds. I need it to disconnect ASAFP!

I've been searing all over the internet trying to figure out how to initiate an immediate disconnection from the peripheral and I found this nifty email that explains a workaround is to unsubscribe from notifications on the service characteristics.

Now I think I'm doing that.. When I want to disconnect I call [connected_device setNotifyValue:NO forCharacteristic:connected_characteristic]

Then, in the didUpdateNotificationStateForCharacteristic function, I have...

if((int)characteristic.isNotifying == 0){
   [manager cancelPeripheralConnection:peripheral];
}

In the function didDisconnectPeripheral...

connected_peripheral = nil;
connected_characteristic = nil;
[connected_peripheral release];
[connected_characteristic release];

I've also taken a good hard look at Apple's CoreBluetooth Temperature Sensor example but it hasn't really helped much....

Any help on this would be amazing!! I just don't know what I'm missing.....

UPDATE: It looks like the app needs to be connected to the bluetooth device for at least a minute before it is allowed to disconnect. If the app is connected for over a minute it will disconnect immediately when the command is sent. Otherwise, it will wait until that one minute mark to actually disconnect.

UPDATE: When I try to disconnect before the one minute mark, I get the following output to the log when the device actually disconnects.

Oct 24 16:49:35 Christophers-iPhone awdd[8168] <Error>: libMobileGestalt copySystemVersionDictionaryValue: Could not lookup ReleaseType from system version dictionary
Oct 24 16:49:35 Christophers-iPhone awdd[8168] <Error>: CoreLocation: CLClient is deprecated. Will be obsolete soon.
Scroop answered 18/10, 2012 at 15:54 Comment(0)
I
7

According to Apple, this new feature is "by design". The way we resolved this issue was to send a command to the Peripheral and have it disconnect from its end. If you do this, then the disconnect is immediate. I do not know why Apple changed this behavior from iOS5 to iOS6 but they must have had their reasons. Of course this solution only works if you have access to the Peripheral firmware and can change it. If there is a different solution, then we have not found it.

Inserted answered 25/10, 2012 at 15:27 Comment(4)
I did [self.peripheralManager stopAdvertising] and [self.peripheralManager removeAllServices] on the peripheral and it still doesn't disconnect immediately. I still see a white-filled bluetooth icon in the top right until the 60-second mark...Totem
"According to Apple"? Where is this (official?) statement?Ineducable
Just wanted to confirm that issue a command to the BLE device to disconnect solved the issues that we were having.Lucillalucille
I am still having this issue on ios 9.1 - any new solutions for this problem?Corking
C
0

That was a bug in iOS 6.0, in 6.1 it's fixed.

Crystalcrystalline answered 20/2, 2013 at 16:30 Comment(4)
No, it's not present in iOS7. Check your device side.Crystalcrystalline
Even if I cancelConnect in didConnect there's a 10s. delay until the physical link is disconnected. The app however considers itself disconnected, it just doesn't receive any data from the peripheral until the the connection is finally severed (10 s later). The docs even claim that there's no guarantee that the physical link will be severed on cancelConnection.Ineducable
As I remember, it's up to device to send disconnection message back to the hub. Perhaps your device do it not so fast.Crystalcrystalline
I've worked with number of BLE devices: HRM, Bike sensor, Key fob - everything disconnects as expected on iOS7.Crystalcrystalline

© 2022 - 2024 — McMap. All rights reserved.