Swift MacOS IOBluetooth无法连接到守护进程

时间:2017-10-10 15:08:50

标签: swift macos runtime-error iobluetooth

我的问题是在第35行,我启动了IOBluetoothDeviceInquiry,它给了我以下错误:Failed to create connection to the daemon: Distributed objects message send timed out这是我的代码不能正常工作:

import Cocoa
import IOBluetooth

class BlueDelegate : IOBluetoothDeviceInquiryDelegate {
    func deviceInquiryDeviceFound(_ sender: IOBluetoothDeviceInquiry, device: IOBluetoothDevice) {
        sender.stop()
        let thingy = device
        print("Found Device: \(thingy.nameOrAddress)")
        print(IOBluetoothDevicePair(device: thingy).start())
    }
}


@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {

    let bt = IOBluetoothDeviceInquiry(delegate: BlueDelegate())

    func applicationDidFinishLaunching(_ aNotification: Notification) {
        // Insert code here to initialize your application
        print("Starting...")
        bt?.updateNewDeviceNames = true
        print("0")
        bt?.stop()
        print("1")
        switch (bt?.start())! {
            case kIOReturnSuccess: print("Success!");break
            case kIOReturnError: print("General Error.");break
            case kIOReturnNoMemory: print("Memory Allocation Error.");break
            case kIOReturnNoResources: print("resource shortage");break
            case kIOReturnIPCError: print("Mach IPC failure");break
            case kIOReturnNoDevice: print("no such device");break

            default:print("Unknown Status.");break
        }
        print("2")
    }

    func applicationWillTerminate(_ aNotification: Notification) {
        // Insert code here to tear down your application
        bt?.stop()
    }


}

我应该怎么做才能解决这个问题,以便我的应用可以继续开发?

提前致谢,

Aaronjam。

0 个答案:

没有答案