5

every since I updated macOS to macOS 12, I have trouble using CoreBluetooth. In one of my apps, I will list all BLE devices using the CGCentralManager class.

This has worked for years. But now, when I start my app, the following output appears in Xcode:

[CoreBluetooth] No name or address
[CoreBluetooth] No name or address
[CoreBluetooth] No name or address
[CoreBluetooth] No name or address
[CoreBluetooth] No name or address

The macOS Console app has many messages like this (I don't know if this is related, the process is bluetoothd instead of my app):

Destroying pairing agent for session <appname>
Erasing session 0x7f795824af00 from SessionMap for "appname-2890-84"
Received 'stop scan' request from session "com.apple.bluetoothd-central-143-2" updateScanParams:YES shouldUpdateState:YES
Stopping scan as there are no remaining scan agents permitted to scan

If my app is not running, the bluetoothd process seems to be rather quiet. Once started, the bluetoothd process seems to have some kind of problem. The question is: which one?

Disabling the Sandbox did not change anything, so I don't think that it has something to do with missing permissions.

I also built a very basic example in a new app. I instantiated a new CBCentralManager and started scanning. The devices were discovered. I my main app, no delegate function is triggered. None at all.

Did anyone encounter the same issue?

inexcitus
  • 2,471
  • 2
  • 26
  • 41
  • 1
    We are seeing something similar (no delegate callback) in https://github.com/hbldh/bleak/issues/635. https://developer.apple.com/forums/thread/687703 suggests disabling filtering duplicates, but that did not make a difference for us. – David Lechner Oct 23 '21 at 17:23
  • I also tried this workaround, but nothing changed. Can you please open a Apple feedback? I think the more people report this issue, the better. Other BLE apps work just fine, which is even more frustrating. – inexcitus Oct 24 '21 at 02:52
  • 1
    Yes, I have reported it. – David Lechner Oct 27 '21 at 15:50
  • Very good. I have submitted a technical support request. I am completely clueless, I have no idea what this could be. Other apps seem to work just fine. – inexcitus Oct 28 '21 at 14:48
  • Any news on this? I have a similar issue... – Sam Washburn Nov 04 '21 at 22:39
  • 1
    Not really. I have created a DTS, Apple wants to clarify this with the Bluetooth engineer, Apple is still investigating. – inexcitus Nov 05 '21 at 04:18

1 Answers1

3

UPDATE: It appears that Apple has fixed the bug in macOS 12.3.


Original answer below applies to 12.0, 12.1 and 12.2.

It appears that Apple has updated macOS to behave more like iOS. The docs for scanForPeripheralsWithServices:options: say:

Your app can scan for Bluetooth devices in the background by specifying the bluetooth-central background mode. To do this, your app must explicitly scan for one or more services by specifying them in the serviceUUIDs parameter. The CBCentralManager scan option has no effect while scanning in the background.

Command line programs cannot ever be considered the foreground app since they are not a .app and therefore the background scanning rules apply. (This is conjecture, but I suspect that NSWorkspace.frontmostApplication might be used to determine the "foreground" application).

If background scanning is acceptable and the Bluetooth devices in use include a service UUID in the advertising data, then a list of service UUIDs can be supplied to scanForPeripheralsWithServices:options:.

If not, then you have to create a signed .app to use foreground scanning.

Some additional details and an ugly workaround for running a command line tool without a GUI as a .app (outside of the XCode debugger) can be found at https://github.com/hbldh/bleak/issues/720. This link is Python-specific but one should be able to extrapolate it to other environments.

David Lechner
  • 1,433
  • 17
  • 29