Bug 7986 - Cannot easily roundtrip CBUUID.ToString() and CBUUID.FromString()
Summary: Cannot easily roundtrip CBUUID.ToString() and CBUUID.FromString()
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: Sebastien Pouliot
URL:
Depends on:
Blocks:
 
Reported: 2012-10-25 10:52 UTC by Kirk Klobe
Modified: 2012-11-06 17:12 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 Kirk Klobe 2012-10-25 10:52:39 UTC
The CoreBluetooth pattern of saving a discovered peripheral's UUID for future reconnection using [CBCentralManager retrievePeripherals] is a bit clunky given the current MonoTouch API surface. It appears that I either have to p/invoke CFUUIDCreateString() or do string fiddling along the lines of:

var uuidString = CBUUID.FromCFUUID(e.peripheral.UUID).ToString ();
var start = uuidString.IndexOf ("<");
var end = uuidString.IndexOf (">");
var guid = uuidString.Substring(start + 1, end - start - 1).Replace (" ","");
var validGuid = guid.Insert (8, "-").Insert (13,"-").Insert (18,"-").Insert (23,"-");

It would be convenient to have a built-in way of getting a string from a CBUUID that can be fed right back into CBUUID.FromString().
Comment 1 Sebastien Pouliot 2012-11-06 08:56:04 UTC
I'm not sure CFUUIDCreateString would help. Apple documentation does not state that CBUUID and CFUUID are tool-free bridged. 

It could be missing (documentation) but CFUUID and NSUUID are documented not to be toll free _and_ there's an API to create a CBUUID from a CFUUID (which would not be needed).

OTOH easy roundtripping is something we should provide.
Comment 2 Kirk Klobe 2012-11-06 09:03:44 UTC
I mentioned CFUUIDCreateString because that is how Apple does it with their TemperatureSensor example:

http://developer.apple.com/library/ios/#samplecode/TemperatureSensor/Listings/TemperatureSensor_LeDiscovery_m.html#//apple_ref/doc/uid/DTS40012194-TemperatureSensor_LeDiscovery_m-DontLinkElementID_7

Thanks for responding and considering it!
Comment 3 Sebastien Pouliot 2012-11-06 17:12:13 UTC
ToString was overriden so it can be used to roundtrip. The old string value is still available with the `Description` property.

There's also a ToString overload that takes a boolean, when using `true` it will "promote" a 16bits UUID into a 128bits UUID, otherwise (false, default), the original size will be kept.

Fixed in
ios6: 028d3e6bd8c056bf1be78b4ac9f789277d413af6
master: 0f3437a42e9382f4c4472488c5472d6344d2aeb9