[Question] Why I am not been able to connect to FBSimulatorHID
A simplified version of my code -
// allocate a simulator from the pool
FBSimulator* sim = [control.pool allocateSimulatorWithConfiguration:[FBSimulatorConfiguration withDeviceModel:simulatorModel]
options: FBSimulatorAllocationOptionsCreate | FBSimulatorAllocationOptionsReuse | FBSimulatorAllocationOptionsEraseOnFree
error: &simulatorApplicationError];
// boot simulator
if(sim.state != FBSimulatorStateBooted) {
[[FBSimulatorLifecycleCommands commandsWithSimulator: sim] bootSimulatorWithError:&simulatorApplicationError];
}
// Get the simulator mach_port_t wrapper
FBSimulatorHID * hid = [FBSimulatorHID hidPortForSimulator:sim error:&simulatorApplicationError];
// connect to Simulator process
[hid connect:&simulatorApplicationError];
When the hid connect method is is called the application goes into an indefinite wait for the mach_msg to return the result. I am not sure why I am not been able to connect to the HID, am I doing something fundamentally wrong here?
On a side-note, I saw this code block in FBSimulatorHID.m / - (BOOL)connect:(NSError **)error
kern_return_t result = mach_msg(handshakeHeader, MACH_RCV_LARGE | MACH_RCV_MSG, 0x0, size, self.registrationPort, timeout, 0x0);The timeout doesn't work here because MACH_RCV_TIMEOUT option is not passed.
You will only be able to connect to FBSimulatorHID if the Simulator was booted from the same process with FBSimulatorBootOptionsEnableDirectLaunch. You cannot connect a FBSimulatorHID instance when the Simulator was booted by any other means, including from a separate process.
The reason for this is that the process that 'boots' the Simulator is responsible for interacting with the mach port and is a limitation of the way the API works; there can't be multiple consumers of the same mach port.
That being said, there should be messaging for this as well so that it is obvious why the API cannot be used.
We just released idb. a new tool that improves significantly over fbsimctl. We recommend switching over. As part of our renewed commitment to this repo we are cleaning up old issues and will be monitoring and reviewing more closely from now on. if you still think this issue is relevant feel free to reopen