2017-12-27 41 views
0

macOS (2017 iMac)에서 블루투스 주변 장치에 액세스하려고 시도했지만 CBCentralManager.poweredOn 상태로 절대 입력되지 않습니다.macOS CBCentralManager 상태가 지원되지 않음

import Cocoa 
import CoreBluetooth 

class BluetoothManager: NSObject { 
    var centralManager: CBCentralManager! 
    override init() { 
    super.init() 
    self.centralManager = CBCentralManager(delegate: self, queue:nil) 
    self.checkState() 
    } 

    func checkState() { 
    print("central state: \(self.centralManager?.state.rawValue ?? -1)") 
    DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + .seconds(2), execute: { 
     self.checkState() 
    }) 
    } 
} 


extension BluetoothManager: CBCentralManagerDelegate { 
    func centralManagerDidUpdateState(_ central: CBCentralManager) { 
    switch central.state { 
    case .poweredOn: 
     print("Power on") 
    case .unsupported: 
     print("Unsupported") 
    default:break 
    } 
    } 
} 


@NSApplicationMain 
class AppDelegate: NSObject, NSApplicationDelegate { 

    var bluetoothManager: BluetoothManager? 

    func applicationDidFinishLaunching(_ aNotification: Notification) { 
    self.bluetoothManager = BluetoothManager() 

    } 

    ... 

} 

이 것입니다 경고 콘솔, Unsupported 지속적으로 출력

[CoreBluetooth] XPC connection invalid 

나는 그 iOS 기기 그냥 생각하지만 내가, 내가 시도 Info.plistNSBluetoothPeripheralUsageDescription, 알고있다.

iMac에서 블루투스를 관리하는 데 잘못된 방향을 찾고 있습니까? 아니면 구현에 뭔가 빠졌습니까? 나는 Core Bluetooth documentation에서 요구되는 모든 것을 다 다루었다고 느낀다.

답변

0

이것은 App Sandbox을 사용 설정 한 것으로 보입니다 (프로젝트 Capabilities에 있음).

Bluetooth (Hardware)을 사용하고 자동 변경 권한 부여 파일을 수락하면 문제가 해결되었습니다.

App Sandbox도 사용 중지 된 것처럼 보이지만 안전하지 않은지 충분히 알 수는 없습니다.

이 참고로, 내 자격이 파일은 이제 다음과 같습니다

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 
<plist version="1.0"> 
<dict> 
    <key>com.apple.security.app-sandbox</key> 
    <true/> 
    <key>com.apple.security.device.bluetooth</key> 
    <true/> 
    <key>com.apple.security.files.user-selected.read-only</key> 
    <true/> 
</dict> 
</plist>