8

I'm using the ASIHttpRequest library to ask a web service every minute for updates. The app receives a json string and parses it. It works OK.

But I'd like to make this more efficient.. what would be the best way of getting the server to send to the app info whenever there is an update.. rather than constantly polling the web service?

cannyboy
  • 24,180
  • 40
  • 146
  • 252

3 Answers3

2

Apple's push notifications may be what you are looking for. However, you'd need to implement something on the website to support them I believe. I haven't used them myself (I haven't gotten that far into my application development), but here is a link to the developer documentation for it: http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Introduction/Introduction.html

Jeremy Dentel
  • 837
  • 2
  • 9
  • 19
2

Apple PUSH notification is not a good solution

1) You can only package a limited amount of data to it 2) It may be difficult to figure out if users have the app launched, or exited. If you keep sending PUSH even after users exit the app, they will end up with lots of spam. If you try to send something to the server to indicate that users have closed the app so it should stop sending PUSH, it may not work when the app crashes.

I suggest you use Sockets.

Or just use a scheduled loop to make requests every minute.

.....

But I wonder if you can just send a PUSH without alert body and sound, and just sending a 0 badge. If app it opened, it will be able to feedback to the server to continue sending update. If there is no feedback, stop sending push .

honcheng
  • 2,014
  • 13
  • 14
  • If I read correctly you specify the attributes with the push notification. You could do a badge and have a function within the application (application:didFinishLoadingWithOptions: I believe) to use ASIHttpRequest to parse the data. This should also improve battery efficiency from the phone as it won't constantly be polling a data source via the internet for data. – Jeremy Dentel Apr 27 '11 at 23:27
  • Is it at all possible to use PUSH notifications to simply send a "trigger" to the client that notifies the application that an update has occured and it should now request the new data from the web service? This way the polling is eliminated? – AJB Dec 26 '12 at 10:03
0

Apple's push notification is one way. Here's a guide on building a push notification provider server.

Todd Hopkinson
  • 6,803
  • 5
  • 32
  • 34