While I couldn't find any official way to get logs from the device, I did manage to write a hack that does so in real time.
It uses a python GUI automation library to pull the text from the Xcode console window.
Please notice this solution does have it's limitations, as it:
- requires the phone to be connected to the computer via cable
- only contains the logs from your own app, thus it falls short of the tools mentioned earlier.
However, it did solve my problem and I'm publishing the short python code in the hopes that it will help other developers.
import atomac
def get_console():
xcode = atomac.getAppRefByBundleId('com.apple.dt.Xcode')
return xcode.windows()[0].groups()[0].textAreasR()[1]
def run():
console = get_console()
while True:
clog = console.AXValue[-1000:]
last_read = clog.split("\n")[-2]
print last_read
if __name__ == "__main__":
run()
Notice you may have to play with some of the indexes inside get_console() to get the console window in your Xcode setup.
(If you're interested, this hack code was written for a hackathon project, as a way to get fast data from the watch since it couldn't send any UDP packets on WatchOS2 Beta 4 and the official ways of sending data from the watch [such as sendMessageData:replyHandler:errorHandler:
] were too slow for what we needed).