No connection notifications callback for Bluetooth devices are called on Sonoma if process is run as daemon/system, works on Ventura. Seems to be some changes in TCC that now requires kTCCServiceBluetoothAlways in system TCC.db - but how to grant this?
Other calls on IOBluetoothDevice fails probably for the same reason.
Running as launch agent works as expected on both Sonoma and Ventura.
Code used
os_log_t logHandle = 0;
@interface BluetoothConnection : NSObject
{
}
@end
@implementation BluetoothConnection
-(id)init {
self = [super init];
if (self)
{
IOBluetoothUserNotification* notification = [IOBluetoothDevice registerForConnectNotifications:self selector:@selector(deviceIsConnected:fromDevice:)];
if (notification == nil)
{
os_log_debug(logHandle, "registerForConnectNotifications failed");
}
else
{
os_log_debug(logHandle, "registerForConnectNotifications %{public}@", notification);
}
}
return self;
}
-(void)deviceDidDisconnect:(IOBluetoothUserNotification*)notification fromDevice:(IOBluetoothDevice*)device {
os_log_debug(logHandle, "%{public}@ (%{public}@) disconnected", [device name], [device addressString]);
}
-(void)deviceIsConnected:(IOBluetoothUserNotification*)notification fromDevice:(IOBluetoothDevice*)device {
os_log_debug(logHandle, "%{public}@ (%{public}@) connected (%d, %d)", [device name], [device addressString], device.deviceClassMajor, device.deviceClassMinor);
[device registerForDisconnectNotification:self selector:@selector(deviceDidDisconnect:fromDevice:)];
}
@end
int main(int argc, const char * argv[])
{
@autoreleasepool
{
logHandle = os_log_create("SPX”, “BT”);
BluetoothConnection *bluetoothConnection = [[BluetoothConnection alloc] init];
[[NSRunLoop currentRunLoop] run];
}
return 0;
}
6
0
1.7k