Reputation: 5103
I am trying to write an iOS app that will notify the user on price changes of products I access as JSON information via an API. I want to have a background task that will repeatedly check the server every n
minutes for new JSON and send the user a notification if certain conditions are met. What would be the correct way to do this?
Upvotes: 2
Views: 1204
Reputation: 16124
As previous posters mentioned, this is better done server side rather than via polling. However, using Apple Push Service to notify the client device is not the ideal solution. The issue is that delivery is not guaranteed (per Apple) and you cannot confirm delivery. The user could decline push notifications, Apple could decline to send the notification if you are sending too many, etc. You are much better off using a service like PubNub
or Pusher
, which push notifications to the client in a reliable way and both have iOS APIs. They are very inexpensive. If you wanted to reinvent the wheel and save money, you could look up how they work and write your own version.
You could of course do client side polling, in which case an asynchronous NSOperation
is particularly well suited (it will run on a background thread and you can post notifications to NSNotificationCenter
when things change). You can find out more about how to implement that here.
Upvotes: 2
Reputation: 1189
This does not work well. Here is a probably better solution:
Upvotes: 0