iPhone 应用程序可以充当服务器来发送消息或推送通知吗? [英] Can an iPhone app act as a server to send messages or push notifications?

查看:37
本文介绍了iPhone 应用程序可以充当服务器来发送消息或推送通知吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个 iOS 应用程序,它可以充当客户端通过蜂窝数据网络连接到其他 iPhone 的服务器(即,没有典型的中央服务器).目标是通过某种通知方式从 iPhone 服务器向多个 iPhone 客户端共享大约 200 条短事件消息,一次一个.Apple Push Notification 服务适用于此类通知,但没有必要专门使用它.

我认为通过从服务 iPhone 连接到 gateway.push.apple.com 可以将推送通知从一部 iPhone 发送到另一部 iPhone,如 本地和推送通知编程指南,但我找不到其他人讨论这种方法(也许它太明显了?).

这一切的原因是为了避免基础设施的开销.如果这不可行,欢迎采用最小化或避免额外硬件的替代方案.

要求:

  • 通信必须[严格]通过蜂窝数据网络
    • 无法使用 Wi-Fi
    • 蓝牙没有足够的范围
  • 与向多个 iPhone 客户端多播的 iPhone 服务器进行单向通信
  • 无越狱
  • 理想情况下,服务电话的电池无需充电即可处理此问题

美国东部标准时间 5 月 4 日凌晨 2 点 12 分更新: 明确地说,我对使用 APN 没有任何特殊要求;我认为在这种设置中它可能是可行的,但从下面的讨论来看,情况似乎并非如此.但是,我仍然对可以帮助我通过某种类型的消息传递或类似形式的通信实现相同最终结果的任何其他系统感兴趣.

解决方案

理论上,您应该能够编写一个 iOS 应用程序,该应用程序可以连接到 APNS 并向运行您的应用程序的其他设备发送通知.但是,您的主要问题将是实际获取其他设备的令牌".当你有一个中央服务器做这项工作时,它总是在线的,因此,客户端可以通过 http 与它对话"并自行注册(在此过程中将他们的令牌提供给服务器).因此,服务器知道客户端令牌,并且可以使用它们通过 APNS 向客户端发送通知.

然而,这在您所谈论的场景中是不可能的.但这并不是说它不可能.可能您可以使用电子邮件帐户 X 来存储所有客户端令牌.每个客户都会向此帐户发送一封电子邮件,其中包含他们的令牌.因此,当另一个客户端"想要向另一个客户端发送通知时,它可以通过查看电子邮件帐户的收件箱来找出令牌(当然,您可以缓存这些内容并以无数种方式对其进行优化).

但关键在于,24/7 全天候在线的(第三方(例如:电子邮件服务提供商)/您自己的)服务器将如何参与该过程.

让我们知道您在这方面的进展情况.知道会很有趣.

I want to write an iOS app that can act as a client and a server to other iPhones over the cellular data network (i.e., without a typical centralized server). The goal is to share series of about 200 short event messages, one at a time, from the iPhone server to multiple iPhone clients by some means of notification. Apple Push Notification service would be fine for such notifications, but there is no need to use it specifically.

I think sending push notifications from one iPhone to another is possible by connecting to gateway.push.apple.com from the serving iPhone as described in the Local and Push Notification Programming Guide, but I can't find anyone else discussing this approach (maybe it's too obvious?).

The reason for all this is an attempt to avoid the overhead of infrastructure. If this isn't feasible, alternatives which minimize or avoid additional hardware are welcome.

Requirements:

  • Communication must be [strictly] over cellular data network
    • Wi-Fi isn't available
    • Bluetooth doesn't have enough range
  • Unidirectional communication with an iPhone server multicasting to many iPhone clients
  • No jailbreaking
  • Ideally the serving phone's battery will be able to handle this without a recharge

Update 5/4/11 2:12 AM EST: Just to be clear, I don't have any particular requirement to use APNs; I thought it may have been feasible in this setup, but from the discussion below, it sounds like that's not the case. However, I'm still interested in any other system that could help me achieve the same end result with some type of message passing or similar form of communication.

解决方案

Theoretically you should be able to write a iOS app that can connect to the APNS and send notifications to other devices running your applications. However, your main problem will be to actually acquire the 'tokens' of other devices. When you have a centralized server doing the job, its always online and thus, the clients can 'talk' to it via http and register them self (giving their tokens to the server in the process). Thus the server knows the client token and it can use them to send notifications to the clients via APNS.

However this is not possible in the scenario you are talking about. But this is not to say its impossible. May be you could use an email account X, to store all client tokens. Every client will send a email to this account with their token in it. So when a another 'client' want to send a notification to another client, it can find out the token by reffering to the inbox of the email account (you can cache this stuff and optimize it in a zillion ways of course).

But the point is some how a (third party(ex: email service provider)/your own) server that is online 24/7 will be involved in the process.

Let us know how you progress with this. It would be interesting to know.

这篇关于iPhone 应用程序可以充当服务器来发送消息或推送通知吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆