如何将简单数据从 iPhone 发送到另一部 iPhone 或 Android 设备?

发布于 2024-10-01 16:28:22 字数 202 浏览 0 评论 0原文

我刚刚开始进行移动开发,经过大量搜索后,我仍然对从 iPhone 向另一台 iPhone 或 Android 设备发送消息感到困惑。例如,在构建一个简单的井字棋游戏时,如果我想通知另一部手机移动,最好的方法是什么? wifi、蓝牙、3G?又如何呢?

许多方法似乎都指向通过网络服务器进行通信,但如果可能的话,我宁愿将它们直接从手机发送到手机。 (当然这是针对本机应用程序的)

I'm just getting started with mobile development, and after considerable searching I'm still confused about sending a message from my iPhone to another or an Android. For instance, in building a simple Tic-Tac-Toe game, if I want to notify the other phone of a move, what is the best way to do so? Wifi, bluetooth, 3G? And how?

Many methods seem to point to communicating through a web server, but I'd rather send them directly from phone to phone if possible. (this is for native apps of course)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

恬淡成诗 2024-10-08 16:28:22

如果您不想拥有服务器(或者即使您想要!这取决于!),听起来您会想要使用 TCP 套接字。 Apple 没有用于 iPhone 到 Android 通信的通用蓝牙 API,无论如何您都可以通过 3G 进行 TCP 访问。 3G 网络连接与 WiFi 非常相似,您应该能够根据需要检查差异,而无需对整体网络代码进行少量更改。我不确定 Android 是否支持 bonjour,但我敢打赌已经有人出于类似原因移植了它,并且 iOS 也支持它。 Apple 有iOS 网络部分,您可能会发现其中的信息。

此外,如果您想留在仅限 iOS 设备的领域内,您可以使用 GameKit 通过蓝牙进行通信。

希望对一些人有所帮助。

If you don't want to have a server (or even if you do! It depends!) it sounds like you will want to use TCP sockets. Apple doesn't have a generic bluetooth API to use with iPhone-to-android communication and you'll have TCP access anyway with 3G. A 3G network connection is very similar to wifi and you should be able to check for the difference as needed with little change to your overall networking code. I'm not sure if bonjour is supported on android, but I bet someone has ported it for similar reasons already, and it is supported in iOS. Apple has a networking section for iOS that you may find informative.

Additionally if you want to stay within the iOS device only realm you could use GameKit to communicate via bluetooth.

Hope that helps some.

浅黛梨妆こ 2024-10-08 16:28:22

最简单的方法是创建一个带有 API 的 Web 服务器,客户端轮询服务器是否有新动作(或者服务器向客户端推送更新)。这是您能够通过 3G 实现此目的的唯一方法,除非您可以找出两部手机的 IP 地址(手机是否会长时间保持相同的 IP 地址?)并在它们之间打开套接字让一部手机作为服务器,另一部手机作为客户端(可能会导致潜在的作弊)。

The easiest way is to create a web server with an API and the clients poll the server for new moves (or the server pushes the client an update). This is the only way you're going to be able to do it over 3G unless you can figure out the IP addresses of both phones (do phones even keep the same IP address for a long period of time?) and open up sockets between them and let one phone be the server and the other be the client (could cause potential cheating).

美胚控场 2024-10-08 16:28:22

WiFi 并不总是存在 - 通过将用户的选择限制在有接入点的区域,您将损失销售。不确定蓝牙 - 它在手机上有多流行,有多少 API 被公开。恕我直言,你最好的选择是 3G。使用某种中央存在服务器(Web 或其他),具有可选代理。阅读点对点网络。

WiFi is not always there - by limiting your users' options to areas with access points, you'll lose sales. Not sure about Bluetooth - how prevalent is it on handsets, how much of the API is exposed. Your best bet, IMHO, is 3G. With some kind of a central presence server (Web or otherwise), with optional proxying. Read up on peer-to-peer networking.

⊕婉儿 2024-10-08 16:28:22

据我所知,iPhone 只支持通过推送通知传入消息。
这意味着您必须通过网络服务等请求来更新信息。
iPhone的蓝牙API也不支持这个。

As far as i know does the iphone only support incoming messages over push notifications.
This means, that you have to update the information, by requesting it from web services etc.
The bluetooth API of the iphone doesn't support this either.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文