【问题标题】:IOBluetooth block by sandbox accessIOBluetooth 通过沙盒访问阻止
【发布时间】:2021-09-09 06:13:34
【问题描述】:

我正在尝试在 MacOS 11.4 上使用 IOBluetooth 和 Xcode 12.5.1 来获取连接到我的计算机的蓝牙设备列表。但是我收到了这个错误。

[用户默认值] 无法读取 CFPrefsPlistSource(域:com.apple.Bluetooth,用户: kCFPreferencesAnyUser, ByHost: Yes, Container: (null), Contents Need 刷新:是):访问应用程序之外的首选项 容器需要 user-preference-read 或 file-read-data 沙箱 访问

在进行一些谷歌搜索并启用 App Sandboxing 中的每个权限并将隐私 - 蓝牙始终使用说明和隐私 - 蓝牙外围设备使用说明添加到 info.plist 之后,我得到了相同的结果。我似乎无法找出导致问题的原因。

这是我的代码:

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
        
    }

}

【问题讨论】:

  • 查看 Info.plist。
  • @El Tomato 我需要添加什么键/值?我尝试添加 Privacy - Bluetooth Always Usage Description 和 Privacy - Bluetooth Peripheral Usage Description 并得到相同的结果
  • 只有三个地方可以看:Capabilities、Info.plist、Development profile。此外,请仔细查看您发布的错误消息。

标签: swift xcode macos cocoa bluetooth


【解决方案1】:

原来我在错误的目标上为 App Sandbox 启用了蓝牙。 (感谢@El Tomato)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-06-13
    • 2015-04-27
    • 1970-01-01
    • 2012-06-26
    • 1970-01-01
    • 1970-01-01
    • 2013-11-07
    • 1970-01-01
    相关资源
    最近更新 更多