Is there any way to read from stdin on an iPhone, whether hardware or emulator?

When I debug an OSX application from Xcode, I can communicate with the application console from the Xcode debugging console - for example, the application can printf() to stdout and displayed on the Xcode debugging console, and my application can call fgets() on stdin to which I can Enter input into the Xcode debug console.

It looks like Xcode when debugging iPhone iOS applications connects stdout ( printf() et. Al., Works fine), but not stdin ?

Has anyone done stdin on iOS / iPhone? This would be very helpful when debugging - even when using the Cocoa iOS app. I could make this work in a more complex way, for example using a socket, but I would prefer Xcode to do this for me.

UPDATE:

Well, that will explain it. The iOS simulator actually opens /dev/null for stdin . You can find out where stdout going (usually /dev/ttys00X ), and then reopen it with O_RDONLY and assign it stdin. This works great for an iOS simulator, but it seems like the linear discipline for connecting the iphone to the iphone device in series is wrong - you can continue to type in the xcode debug console and never go to the iphone hardware (and your program runs on the iPhone hardware just sits, expecting something to appear on stdin aka /dev/ttys00X ).

I wonder if there is a way to make this work with iPhone hardware?

+4
source share
1 answer

I have no solution to this exact problem, and it is entirely possible that there is no way to do this. I have an alternative suggestion. I used it in one of my projects and it worked quite well.

I used the AsyncSocket library to implement a micro TCP server with which I could connect to telnet and communicate with my application. There are several advantages to this approach:

  • you do not need to run under the debugger
  • the application is accessible from any computer
  • it is possible to access the application on another phone (conveniently in a team)
  • this is a script (may contain several commands)
  • extensible (it is easy to make an HTTP server from this to connect to the browser)
+2
source

Source: https://habr.com/ru/post/1336383/


All Articles