i am trying to work with external accessory api , wrote some code but i gets big error. can someone tell me please, where is my problem?
this is what i wrote and the error that i get
maybe that would help my last question as well
thanks
var acs = EAAccessory()
override func viewDidLoad() {
super.viewDidLoad()
let accessorys = EAAccessoryManager.shared().connectedAccessories.first
if accessorys != nil{
acs = accessorys!
acs.delegate = self
}
let session = EASession(accessory: acs, forProtocol: acs.protocolStrings.description)
if session != nil {
session?.outputStream?.delegate = self
session?.outputStream?.schedule(in: RunLoop.main, forMode: RunLoopMode.defaultRunLoopMode)
session?.outputStream?.open()
session?.inputStream?.delegate = self
session?.inputStream?.schedule(in: RunLoop.main, forMode: RunLoopMode.defaultRunLoopMode)
session?.inputStream?.open()
}
}
Terminating app due to uncaught exception 'EAAccessoryInitException', reason: '-init not supported. EAAccessoryManager is responsible for creating all objects.' *** First throw call stack: (0x1d963b3d 0x1cbeb067 0x1d963a85 0x29bcdf85 0xdfa24 0xdd2b8 0xdee68 0xdf03c 0x230663bb 0x231a06ef 0x231a03a5 0x230660d3 0x231a06ef 0x231a0647 0x231a03a5 0x23065633 0x232f5b1f 0x22e0ce41 0x22c052a1 0x22e0bb11 0x22e1e7c5 0x22e0935b 0x1f244c13 0x1f244acd 0x1f244db7 0x1d91ffdd 0x1d91fb05 0x1d91df51 0x1d8711af 0x1d870fd1 0x22bfee2d 0x22bf9a53 0xe0b18 0x1d05e4eb) libc++abi.dylib: terminating with uncaught exception of type NSException
This line is not valid:
var acs = EAAccessory()
You can't create an "empty" EAAccessory.
Given how you're doing this, you probably meant:
var acs: EAAccessory!
or
var acs: EAAccessory?
That said, I would generally recommend moving your accessory handling out of view controllers and into the model layer. View controllers generally should just focus on coordinating views. They're not for driving interactions with hardware.