iOS 聊天 APNS、套接字或时间间隔 [英] iOS chat APNS, sockets or time interval

查看:24
本文介绍了iOS 聊天 APNS、套接字或时间间隔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 iPhone 制作一个聊天应用,但我不确定对话消息应该如何立即出现.

I'm making a chat app for iPhone, but im not sure how conversation messages should come instantly.

我已经阅读了大量有关此主题的 Google 搜索结果.还有一次:
- http://www.raywenderlich.com/3932/how-to-create-a-socket-based-iphone-app-and-server
- http://www.raywenderlich.com/3443/apple-推送通知服务教程第 12 部分

I have read tons of Google results on this topic. Also the once on:
- http://www.raywenderlich.com/3932/how-to-create-a-socket-based-iphone-app-and-server
- http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12

APNS 方法:
一条不可见的通知将被推送到 iPhone,表明一条新消息已准备好被阅读.因此该应用程序将请求未读消息.因此,我不会手动轮询新消息,而是让 APNS 提供帮助.但我不确定?

APNS approach:
An invisible notification will be pushed to the iPhone indicating that a new message is ready to be read. So the app will make a request for unread messages. So instead of manually polling new messages, I will let APNS help with that. But I'm not sure?

套接字方法:
建立一个开放的套接字连接以共享数据.当在 db 中发现新消息时,它会自动将数据发送到应用程序.但是 IP 范围、防火墙、功耗和其他方面呢?我又不确定:(

Sockets approach:
Making a socket connection that is open to share data. When new messages is found in db, it will automatic send the data to the app. But what about IP range, firewall, power consumption, other things? again I'm not sure :(

投票方式:
设置一个轮询请求的时间间隔,功耗是我的敌人.

Polling approach:
Make a time interval where I poll request, power consumption is my enemy here.

我的问题:
-哪种方法最好?
- 其他建议?
- 我真的需要有这方面经验的人的一些利弊.

My question:
- Which approach is best?
- Other suggestions?
- I really need some cons and pros from people with experience on this topic.

例子总是好的.
谢谢

Examples is always good.
Thanks

推荐答案

我认为您主要关心的是如何在您的应用程序处于后台时接收新消息.因为当我可以通过 WhatsApp 等应用接收通知时,我不会整天打开一个即时通讯应用.

I think your main concern is how to receive new messages while your application is in the background. Because it's not like I'm going to have a messenger app all day open when I can get notifications with apps like WhatsApp.

比 TCPIP 套接字更好,您可以使用 websockets.由于它是 HTTP,因此没有防火墙问题,但是需要与前台应用程序建立永久连接,这会耗尽电池电量.

Better than TCPIP sockets you could use websockets. Since it is HTTP there are no firewall problems, BUT that requires a permanent connection with application on the foreground which drains the battery.

而且由于只允许在后台运行音乐、位置或语音 ip,除非应用程序打开,否则您无法进行轮询.请注意,如果您注册这些后台任务并执行其他操作,Apple 会注意到并拒绝您的应用.

And because only music, location, or voice ip, is allowed to run on the background, you can't poll unless the application is open. Note that if you register for those background tasks and do something else Apple will notice and reject your app.

因此,使用APNS.这就是 WhatsApp 所做的.

Therefore, use APNS. That's what WhatsApp does.

这篇关于iOS 聊天 APNS、套接字或时间间隔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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