简体   繁体   English

iOS与OS X通讯

[英]iOS communicating with OS X

I'm looking for a pointer in the right direction to get started with writing an iPhone app that sends commands to OS X, for example telling OS X to sleep. 我正在寻找正确的方向,以开始编写可向OS X发送命令的iPhone应用程序,例如告诉OS X进入睡眠状态。 I can't seem to find the relevant part of the documentation? 我似乎找不到文档的相关部分?

AFAIK, most apps have been performing this kind of communication with a client/server design, where a "server" app runs on the host OS X machine, and a "client" app on the iOS device connecting using some sort of protocol (HTTP? Bonjour?). AFAIK,大多数应用程序一直在与客户端/服务器设计进行这种通信,其中“服务器”应用程序在主机OS X计算机上运行,​​而iOS设备上的“客户端”应用程序使用某种协议(HTTP ? 你好?)。

You won't find this in the documentation because this is a niche design pattern that few apps need (especially since documents can now be shared more easily with the new version of iOS and iTunes). 您不会在文档中找到此内容,因为这是一种很少有应用程序需要的利基设计模式(尤其是因为现在可以更轻松地与新版本的iOS和iTunes共享文档)。

iOS doesn't support ObjC remote objects, which would be the easiest way to communicate between two OS X machines. iOS不支持ObjC远程对象,这是在两台OS X机器之间进行通信的最简单方法。

An alternative to the HTTP client/server approach could be making your iPhone app connect in via a remote Unix shell to the OS X machine (via ssh) and then issuing Unix or AppleScript commands to perform your system actions. HTTP客户端/服务器方法的一种替代方法是使您的iPhone应用程序通过远程Unix外壳(通过ssh)连接到OS X计算机,然后发出Unix或AppleScript命令来执行系统操作。

You could also set up a socket connection. 您还可以设置套接字连接。 I have done a app for Android, that does exactly the same for Windows computers. 我为Android开发了一个应用程序,与Windows计算机完全相同。 The app is in use in a computer store :) 该应用程序正在计算机商店中使用:)

For Mac, you have to use sudo command, so you need the user to type in password, on first use. 对于Mac,您必须使用sudo命令,因此您需要用户在首次使用时输入密码。

Then the server application on the Mac can send "sudo shutdown -h now" to the terminal when the server application gets a predefined byte stream on the socket input. 然后,当服务器应用程序在套接字输入上获得预定义的字节流时,Mac上的服务器应用程序可以向终端发送“ sudo shutdown -h now”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM