简体   繁体   English

如何创建一个从iOS应用程序通过WiFi网络接收数据的小型Mac应用程序?

[英]How can I create a small Mac app that receives data over the WiFi network from an iOS app?

What I need is to have a simple screen in this Mac app that just prints a string as the iPhone is transmitting strings through the WiFi network. 我需要的是在这个Mac应用程序中有一个简单的屏幕,只需打印一个字符串,因为iPhone正在通过WiFi网络传输字符串。

This string is simply a string value from a slider being adjusted up and down by the user on the iPhone. 该字符串只是来自用户在iPhone上上下调整的滑块的字符串值。 The data will be sent to the Mac app and then the Mac app will receive this signal from the WiFi network and simply print the values. 数据将被发送到Mac应用程序,然后Mac应用程序将从WiFi网络接收此信号并简单地打印值。

This is a constant connection. 这是一个持续的连接。 I'm not trying to sync once. 我不想尝试同步一次。 I'm trying to listen to the iPhone device from the Mac to see if the iPhone is sending any more strings as the user slides the UISlider up and down from the iPhone app. 我正试图从Mac上听iPhone设备,看看当用户从iPhone应用程序上下滑动UISlider时,iPhone是否正在发送更多字符串。

How can I create the client side? 我该如何创建客户端? Do I need to use Bonjour or something? 我需要使用Bonjour吗?

In my answer to this question , I provide a link to a sample application that has a Mac component and an iPhone one . 这个问题的回答中 ,我提供了一个指向具有Mac组件iPhone 组件的示例应用程序的链接。 These components communicate between one another over a WiFi network, with changes in a label on one being reflected in the other. 这些组件通过WiFi网络在彼此之间进行通信,其中一个标签的变化在另一个上反映。 This is done using Bonjour discovery and the standard networking APIs. 这是使用Bonjour发现和标准网络API完成的。

With simple modifications, this could be used to send the continuous updates you need for your particular case. 通过简单的修改,这可以用于发送您的特定情况所需的连续更新。

Use the CFNetwork framework, you can use bonjour for discovery and then handle a persistent connection through native sockets for passing data back and forth. 使用CFNetwork框架,您可以使用bonjour进行发现,然后通过本机套接字处理持久连接以来回传递数据。

http://developer.apple.com/library/ios/#documentation/Networking/Conceptual/CFNetwork/Introduction/Introduction.html http://developer.apple.com/library/ios/#documentation/Networking/Conceptual/CFNetwork/Introduction/Introduction.html

Here is an excellent tutorial to get started, its for iOS but CFNetwork is available in OS X too. 这是一个很好的入门教程,适用于iOS,但CFNetwork也可以在OS X中使用。

http://mobileorchard.com/tutorial-networking-and-bonjour-on-iphone/ http://mobileorchard.com/tutorial-networking-and-bonjour-on-iphone/

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

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