iOS chat APNS, sockets or time interval [closed]

不问归期 提交于 2019-12-03 05:45:56

问题


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

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 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?

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


回答1:


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.

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.

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.

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




回答2:


Use XMPP SERVER for chat purpose

http://mobile.tutsplus.com/tutorials/iphone/building-a-jabber-client-for-ios-xmpp-integration/

I hope this link will be useful to you.



来源:https://stackoverflow.com/questions/11271758/ios-chat-apns-sockets-or-time-interval

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!