-->

Communication between two iOS devices

2020-02-19 08:32发布

问题:

I am looking for a way to have one iPhone app send a message to another app on a different phone (sort of like a Sender-Receiver set up). I am looking for the best possible way to do this. Does anyone have any ideas and/or tutorials?

Thanks for the help.

回答1:

You should use GameKit. It is super easy to send messages between two iOS devices using it. Here's a great tutorial: Game Kit. You can also get more information about it here from the docs: About Game Kit.

You communicate by creating an ad-hoc bluetooth or local wireless network.



回答2:

lmirak provided insightful info about device communication(especially about GameKit). I would like to add one more solution. You can use WiFi network to do your device communication.

See the link or download the sample application from developer.apple

The sample application named as WiTap. It demonstrates how to achieve network communication between applications. Using Bonjour, the application both advertises itself on the local network and displays a list of other instances of this application on the network.



回答3:

If your app is only going to run on iOS, then you should use the fantastic MultipeerConnectivity library. https://developer.apple.com/documentation/multipeerconnectivity


If you need a solution that will work cross-platform, then one way to accomplish this is using sockets and connecting over a local network. On iOS you can use CocoaAsyncPods for sockets and NetService for discovery.

Here is a basic example app that does this: https://github.com/brendaninnis/LocalNetworkingApp , which I explain in great detail here: http://brendaninnis.ca/connect-nearby-devices-part-1.html