Home > Mobile >  IOBluetooth block by sandbox access
IOBluetooth block by sandbox access

Time:09-18

I'm trying to use IOBluetooth with Xcode 12.5.1 on MacOS 11.4 to get a list of bluetooth devices connected to my computer. However I'm getting this error.

[User Defaults] Couldn't read values in CFPrefsPlistSource<0x600000af6b80> (Domain: com.apple.Bluetooth, User: kCFPreferencesAnyUser, ByHost: Yes, Container: (null), Contents Need Refresh: Yes): accessing preferences outside an application's container requires user-preference-read or file-read-data sandbox access

After doing some google searching and enabling every permission in App Sandboxing and adding Privacy - Bluetooth Always Usage Description and Privacy - Bluetooth Peripheral Usage Description to info.plist I get the same result. I can't seem to find out what's causing the problem.

Here's my code:

import Cocoa
import IOBluetooth

class ViewController: NSViewController {

let ioBluetoothDevice = IOBluetoothDevice()

override func viewDidLoad() {
        super.viewDidLoad()

        print(IOBluetoothDevice.pairedDevices() ?? "No Paired Devices") // <- returns empty array even though I have a keyboard and mouse connected
        
    }

}

CodePudding user response:

Turns out I had enabled Bluetooth for the App Sandbox on the wrong target. (Thanks @El Tomato)

  • Related