17

I'm developing a Bluetooth LE device and am having trouble because of MacOS's caching of the services. If I try to delete a service or change its UUID on the device I'm developing, the change doesn't show up on the Mac and instead I continue seeing the old list of services and UUIDs from the device. I tried going to another Mac that hadn't paired with my device and it saw the new list of services with the correct UUIDs, so it seems to be a caching issue with my development Mac.

I found the com.apple.Bluetooth.plist file in /Library/Preferences and deleted it, but the system put it back with the same data, I presume the system has the cache loaded into memory and is just writing it back out when needed.

Does anybody know how to wipe the MacOS CoreBluetooth device/service cache?

John Stephen
  • 7,625
  • 2
  • 31
  • 45

2 Answers2

37

I finally found the source of the problem -- there's a cache in the user preferences folder in a folder named ByHost. Here are the steps to clear the Bluetooth cache:

  • Turn off Bluetooth
  • Delete com.apple.Bluetooth.plist from /Library/Preferences
  • Delete files named com.apple.Bluetooth.somehexuuidstuff.plist from ~/Library/Preferences/ByHost (note that this is the user preference folder, not the system one)
  • Turn on Bluetooth

After doing that my peripheral's services are correctly identified. From what I found on the web, there may also be some other com.apple.Bluetooth files in /Library/Preferences related to HIDs or headsets or something -- I don't know if it's important to delete those as I didn't have them on my system.

John Stephen
  • 7,625
  • 2
  • 31
  • 45
  • I've run into this issue a lot on my devices. For iOS (not OSX), I've found that on iOS, it's sufficient about 80-90% of the time to simply turn the BT off and on to eliminate the caching problems. The other 10-20%, I do a device restart, and it works. – SJoshi Jun 21 '15 at 17:38
  • Every update to El Capitan 10.11.x has required me to delete the "ByHost" plist files for Bluetooth to work again, but I have to reboot first. – doublesharp Dec 16 '15 at 19:39
  • 1
    Tried this with Sierra and when I turn bluetooth back on, the 19950 items in CoreBluetoothCache are still in the newly created com.apple.Bluetooth.plist – Neth Dec 21 '17 at 17:25
  • This solved a problem where my 16" MacBook Pro running Big Sur kept reconnecting to a bluetooth speaker device. This was the only way I found that could remove the device permanently. – Simon Fredsted Jun 01 '21 at 13:03
  • Update: It didn't actually solve the problem. What ended up solving it was downloading a legacy version of Bluetooth Explorer from the Mac developer's portal, and disabling "Simple Pairing". After that, it seems the device would actually ask before each pairing. I could then check "ignore this device". After this, it seems the continuous auto pairing from the device has stopped. What a mess, Apple's software quality has really gone downhill lately. – Simon Fredsted Jun 02 '21 at 08:24
0

You can also clear the cache via the following command in the Terminal:

sudo rm /Library/Preferences/com.apple.Bluetooth.plist && sudo shutdown -r now

This does what John explained earlier; make sure you have no ongoing / unsaved processes taking place (since this command will restart your machine).