2014-03-31 40 views
2

我正在關注如何實現Mac RFCOMM服務器的Mac Developer庫中的「藍牙設備訪問指南」。通過對如何將服務定義添加到SDP數據庫中的導向部的方式存在使用不推薦使用功能的代碼:OSX棄用的藍牙功能

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

Apple documentation

在谷歌上搜索這個功能我發現了幾個開源項目仍然使用該功能。我也發現了一些更改日誌說,這個功能已經被移除了,我發現了一些頭文件說明如下:

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. 

在此基礎上,我的問題是:

  • 爲什麼在Mac文檔使用不推薦的函數?
  • 什麼是Objective-C等價物?

回答

2

顯然的:

IOBluetoothAddServiceDict 

功能也被廢棄了(但仍然可用)。相反,我應該使用

+[IOBluetoothSDPServiceRecord publishedServiceRecordWithDictionary:] 

這似乎並不需要使用釋放功能。

+0

剛剛遇到同樣的事情,你有可能發佈你的更新代碼嗎? –

+0

@AdamMcCormick這是我的代碼的樣子。 https://gist.github.com/ui-philip/78897d6f304aa9411bcb。請記住,您還需要一個BluetoothService.plist文件。 – pqvst

+0

謝謝,這比官方文檔更清潔。如果你願意分享,我很樂意看到你的plist。 –