Search code examples
macosbluetoothiobluetooth

OSX deprecated bluetooth functions


I am following the "Bluetooth Device Access Guide" in the Mac Developer library, regarding how to implement a Mac RFCOMM server. Part way through the guide on how to add a service definition to the SDP database there is a code listing that uses a deprecated function:

// Now that we have an IOBluetoothSDPServiceRecord object,
// we no longer need the IOBluetoothSDPServiceRecordRef.
IOBluetoothObjectRelease( serviceRecordRef );

Apple documentation

When googling this function I found several open-source projects that still use the function as well. I also found some change logs saying that this function has been removed, and I found some header documentation stating the following:

The ref counting scheme allows the IOBluetoothObjectRefs to be freed 
when they are no longer used. When the ref count reaches zero, 
the target object will be freed.

***      DEPRECATED IN BLUETOOTH 2.2 (Mac OS X 10.6) ***      
You should transition your code to Objective-C equivalents. ***      
This API may be removed any time in the future.

Based on this, my questions are:

  • Why is the Mac documentation using a deprecated function?
  • What is the Objective-C equivalent?

Solution

  • Apparently the:

    IOBluetoothAddServiceDict
    

    function has also been deprecated (but is still available). Instead, I should be using

    +[IOBluetoothSDPServiceRecord publishedServiceRecordWithDictionary:]
    

    which doesn't seem to require the use of the release function.