Bug 7452 - CoreBluetooth CBPeripheral cannot discover services
Summary: CoreBluetooth CBPeripheral cannot discover services
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: 6.0.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-09-25 14:41 UTC by Josh
Modified: 2012-09-26 15:43 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Josh 2012-09-25 14:41:33 UTC
In my CentralDelegateManager subclass I override RetrievedConnectedPeripherals. In that method I iterate through my CBPeripheral[] and for each peripheral I have tried both setting its delegate to a CBPeripheralDelegate subclass and hooking up to the DiscoveredService event. Then I call peripheral.DiscoverServices. I have tried both passing in the specific CBUUID for the service on my peripheral and passing in null in which case it should discover any CBServices. 

However, neither the CBPeripheralDelegate DiscoveredService method nor my event handler for DiscoveredService ever get fired. In the Apple documentation it seems that the callback should be fired whether successfully or not, if unsuccessful there should be a non null NSError parameter passed in.

As an aside, when calling peripheral.DiscoverServices the current api is not great for passing in null because there is a CBUUID[] and a Guid[] passing in a simple null value is an ambiguous method call. So I have to declare:

CBUUID uuids[] = null;
peripheral.DiscoverServices(uuids);

which is not great.

I have been using the Wahoo Heart Rate Monitor to test this, as well as my own iPad 3 running as a CBPeripheralManager.

I ALWAYS get the didDiscoverServices callback invoked if I use Xcode, so the issue is most likely in MonoTouch. Additionally even though all the peripherals passed into RetrievedConnectedPeripherals are actually connected, peripheral.IsConnected always shows false. I'm sure this is related to the lack of a callback or event for service discovery.

Thanks,

Josh
Comment 1 Rolf Bjarne Kvinge [MSFT] 2012-09-25 18:17:42 UTC
Can you show all the bluetooth related code you have?

This is unfortunately something I can't debug myself, since I'd need to get a bluetooth device, but maybe I have any ideas what you can try out if I see your code.
Comment 2 Josh 2012-09-26 15:43:52 UTC
Please disregard this. Turns out this isn't a Xamarin bug. 

It's not an Apple bug either, but rather my confusion around how CoreBluetooth works due to Apple not providing useful documentation for it. 

From trolling the dev forums I've found some useful information about this which is under NDA.