2017-12-27 30 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.plistキーNSBluetoothPeripheralUsageDescription、の認識しています。

iMacでブルートゥースを管理するのが間違っていますか?それとも私の実装は何か不足していますか? Core Bluetooth documentationで必要なものすべてをカバーしたような気がします。

答えて

0

App Sandboxが有効になっていると考えられます(プロジェクトCapabilitiesにあります)。

BluetoothHardware)を有効にして、権限変更ファイルへの自動変更を承認すると、問題が解決されました。

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>  
:参考までに、私の資格ファイルは次のようになります

関連する問題