How do I write a .txt file on my macOS Desktop while running an iOS app on XCode?

时间:2017-04-24 17:35:58

标签: ios swift macos swift3 xcode8

I want to get coordinates from a UIImageView and transfer them through serial into an Arduino. I was thinking about writing the coordinates into on a .txt on my MacOS Desktop, which can be parsed through regular C++ file handling. This is only during development. The final app will probably use Bluetooth.

I've looked into the Foundation API Reference, and it all lead to file directories on my iPhone instead of file directories on my MacOS. Is it possible to retrieve information from XCode and store it on MacOS instead of iOS?

Or, am I just better off transferring this data to the Arduino through Bluetooth?

1 个答案:

答案 0 :(得分:0)

假设您在实际 iPhone设备上运行时在开发期间需要 ,您可以尝试2个选项:

<强> HTTP 即可。您可以在macOS上启动一个简单的Web服务器,然后使用来自iOS端的纯HTTP发送所需的数据。

Python提供SimpleHTTPServer,但我认为它还不支持PUT或POST命令。但this one确实如此。

<强>套接字即可。在您的macOS上,侦听任意TCP端口(例如8000)并将输出重定向到文本文件:

nc -k -l 8000 > ios.txt

你可以像这样测试它(在macOS上):

echo foo | nc localhost 8000

最后,在iOS端,使用标准套接字发送数据。