本文介绍了服务器到客户端的消息可以依靠APNS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个消息应用程序,我有一个关于如何从服务器发送数据到客户端的困境。

I'm working on a messaging app and I have a dilemma about how to send data from server to client.

我使用的是集中式服务器设计,其中客户端使用 NSURLConnection的将消息发送到服务器,服务器不会保存和管理开放式插座,不能发送邮件的客户之一。因此,客户端使用一个定时器和查询服务器每2秒钟,看看新的数据正在等待他们。

I'm using a centralized server design, where clients uses NSURLConnection to send messages to the server, the server doesn't keep and manage open sockets and can't send a message for one of the clients. So clients use a timer and query the server every 2 seconds to see if new data is waiting for them.

这种方法的问题在于,轮询一次2秒似乎杀电池非常快的服务器,所以我想,也许,而不是客户端轮询服务器,为使用APNS * 服务器,所以当有一些的新的信息 **客户端,服务器会发送一个推送通知 * 的**给客户端,客户端将获取来自服务器的数据。

The problem with this approach is that polling the server every 2 second seem to kill the battery very fast, so I thought maybe instead of clients polling the server, to use APNS* so when the server has some new information ** for the client, the server will send a push notification *** to the client, then the client will fetch the data from the server.

*使用APNS - 如果客户允许的话,客户当然可以禁用此选项。所以我会检查是否允许推送应用程序进入前景,如果没有,我会回到轮询方法每次

* use APNS - if client allows it, client can of course disable this option. So I will check if push allowed every time the app enter foreground and if not I'll return to the polling approach.

** 新信息可以从短信到服务器管理员的邮件什么。 (也有很多管理信息......)结果
例如,在我的应用程序的用户可以看到他们的朋友的状态(在线/离线),所以如果user1和user2是朋友,和user2只是改变从网上他的状态为脱机状态,则服务器需要发送新信息(管理信息= user2_offline )中的user1。

** New information can be anything from text messages to server admin messages. (and there are a lot of admin messages...)
For example, in my app users can see their friends status (online/offline), so if user1 and user2 are friends, and user2 just change his status from online to offline, then server needs to send this new info (admin message = user2_offline) to user1.

的*** 的推送通知服务器将是空的(没有数据/声音),它只是为客户端触发获取新的信息,所以如果一推被发送到客户端和客户端应用程序接近,他也不会注意到什么。 (如果应用程序正在运行,那么它会读取来自服务器的新的信息)

*** The push notifications server sends are empty (with no data/sound), it's just a trigger for the client to fetch the new info, so if a push was sent to the client and the client app was close, he will not notice anything. (if the app is running, then it will fetched the new info from server)

请问有需要大量推送通知了大规模的消息应用这种方法的工作使用?

要更清楚我的主要问题是:结果
1.是否APNS足够可靠的,我可以用它作为我的核心服务器到客户端的消息机制?结果
2.将苹果批准潜在的几千或几十万推一天通知从我的服务器?

To be clearer my main concerns are:
1. Is APNS reliable enough that I can use it as my core server-to-client messaging mechanism?
2. Will apple approve potentially thousands or hundreds of thousands push notifications a day from my server?

推荐答案

我已经在这个领域了一会儿,从我的经验,适度的工作,我觉得你的方法来解决你的问题将无处找到您。首先请允许我强调的APN特性一些重要的事实:

I have worked in this area for a while and from my modest experience I think your approach to solve your problems will reach you nowhere. Allow me first to highlight some important facts on the APN characteristics:


  1. 的APN是不可靠的,他们不是100%保证到达客户端。

  2. 作为苹果公司的文档,是的APN的尽力而为,所以很多时候他们可能达不到。

  3. 的APN不抱在他们里面的数据,所以即使他们到达您的客户端应用程序,他们持有在他们里面没有任何的应用程序。

  4. 的APN是的东西与你的应用程序已发生用户只需通知,同时有消息(出现在APN的警告框,文本)是由iOS的处理,而不是你的应用程序。这就是为什么与iOS 4设备将在除与iOS 5的设备以不同的方式显示APN,它是操作系统的工作不是你的应用程序。

  5. 当通知来的是你的服务器的责任,而不是设备操作系统上的应用程序图标将出现徽章的价值。换句话说,当一个APN达到它应该有你的应用程序的新通知的计数值的设备。操作系统不会为这个做任何事情。

  1. APNs are not reliable, they are not 100% guaranteed to reach the client.
  2. As of Apple's documentation, APNs are best effort, so many times they might not reach.
  3. APNs don't hold data inside them, so even if they reach your client app they hold nothing inside them for the app.
  4. APNs are just notifications for the user that something related to your app has occurred, while there message (the text that appears in the Alert Box of the APN) is handled by the iOS and not your app. This is why devices with iOS 4 will display the APN in a different way than devices with iOS 5, it is OS job not your app.
  5. The badge value that appears on your app icon when notifications come is the responsibility of your server, and not the device OS. Put differently, when an APN reaches the device it should come having the new notification count value for your app. The OS won't do anything for this.

说到这里我想解释一下这样的应用程序是如何通常设计。首先,它不是由URL连接完成,客户端不检查服务器的时间每个周期。通常你有一个客户机/服务器架构,客户端是设备上的应用程序和服务器是驻留在服务器上一个真正的服务器程序。该服务器可以是微软(使用C#为例)或MAC(使用Objective C)。服务器具有它存储在它里面的信息的数据库。一些重要的信息(与你的问题)是APN的计数值,要传递消息,客户如果联机或脱机。状态

Having said that I would like to explain a bit how usually such applications are designed. First, it is not done by URL Connections and the clients don't check the server every period of time. Usually you have a client/server architecture where your client is the app on the device and the server is a real server program that resides on a server machine. The server could be Microsoft (using C# for example) or MAC (using Objective C). The server has a database that it stores information inside it. Some important information (related to your question) is the APN Count Value, the Message that you want to deliver, the state of the client if online or offline.

当一个客户喜欢送东西到另一个客户端,或者当服务器要送东西给客户端(或所有客户端),检查收件人客户端,看他是否是在线还是离线。如果他是在网上的消息直接发送,通常在通信上的TCP套接字进行。如果用户离线则服务器将存储需要被发送到客户端的消息,增加所述APN计数值,发送的APN到收件人。当收件人变为联机时,服务器会发现,(因为建立连接和握手),因此将会从数据库中获取所有未传递的消息,并将其发送给他...

When a client likes to send something to another client, or when the server wants to send something to a client (or all the client), a check is made to the recipient client to see if he is online or offline. If he is online the message is sent directly, and usually the communications are done on TCP Sockets. If the user is offline then the server will store the message that needs to be sent to the client, increase the APN Count value, send an APN to that recipient. When that recipient becomes online, the server will notice that (because there is establish connection and handshaking) and therefore will fetch all undelivered messages from the database and send them to him...

这是一个漫长的过程,我希望我能够解释的事情有点给你。在任何情况下,我不认为你的方式是可行的,或使你达到真正的工作。

It is a long process, I hope I was able to explain things a bit to you. In all cases I don't think your way is practical or enables you to reach real work.

这篇关于服务器到客户端的消息可以依靠APNS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 08:59
查看更多