import ExternalAccessory
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(didConnectAccessory(_:)), name: Notification.Name.EAAccessoryDidConnect, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(didDisconnectAccessory(_:)), name: Notification.Name.EAAccessoryDidDisconnect, object: nil)
}
@objc
private func didConnectAccessory(_ notification: NSNotification) {
let accessoryManager = EAAccessoryManager.shared()
for accessory in accessoryManager.connectedAccessories {
if accessory.protocolStrings.contains(communicationProtocol) {
//We have found the accessory corresponding to our gadget
let description = """
Accessory name: \(accessory.name)
Manufacturer: \(accessory.manufacturer)
Model number: \(accessory.modelNumber)
Serial number: \(accessory.serialNumber)
HW Revision: \(accessory.hardwareRevision)
FW Revision: \(accessory.firmwareRevision)
Connected: \(accessory.isConnected)
Connection ID: \(accessory.connectionID)
Protocol strings: \(accessory.protocolStrings.joined(separator: "; "))
"""
print(description)
}
self.accessory = accessory
}
}
@objc
private func didDisconnectAccessory(_ notification: NSNotification) {
print("disconnect")
}
网友评论