iOS APNS "best-effort" fallback
Asked Answered
B

2

0

I cannot seem the have my head around this. APNS as stated in the documentation has best-effort delivery, i.e. delivery is not guaranteed. However, if I am to use the push-notification model in my client/server application, I have to use them somehow.

The general model looks as follows: there is new data on the server -> the server then sends a push notification informing the client(s) that there is new data available -> client downloads new data.

The question is then, if I cannot rely 100% on the notification to be delivered, what kind of fallback mechanism can I use so that I can ensure that the client receives the new data available on the server ? What is the way to ensure that the client has the most-up-to-date data using APNS ?

Boyish answered 10/10, 2014 at 15:22 Comment(0)
G
3

What is the way to ensure that the client has the most-up-to-date data using APNS ?

There is no way to do this with just APNS. Your client needs to query your server when the app is brought to the foreground to see if there is new data, regardless of any push notifications you may have lost or received.

Gyatt answered 10/10, 2014 at 15:24 Comment(13)
Yeah, I was thinking the same thing pretty much. What I can't understand is - what is the point of APNS if the client will be querying the server every time the app is brought to the foreground anyway? And in retrospect that makes me think that if I cannot rely on the APNS what is the point of using them at all if I have to query the server anyway ? Thanks.Boyish
The point is to be able to show an alert or trigger some other action on the device while the app is in the background. Or to allow the app to avoid polling for new data while in the foreground. Checking for new data when the app is brought forward is a lot less frequently than polling every N seconds/minutes.Gyatt
So if the app is in the foreground and the user is interacting with it, and there is new data on the server and the notification is not delivered - then how would the client know to get the new data ? The only option I see is either polling or do something stupid like updating data on every viewWillAppear:Boyish
Your question is more-or-less equivalent to "If the app is in the foreground and there is new data on the server, but the polling request for new data fails, how would the client know to get the new data?" You'll have to design around the fact that sometimes the data is not immediately available. Honestly, asking the server if new data is available in viewWillAppear is very common, but clearly it depends on how much data you're talking about.Gyatt
Many thanks for the input. I am slowly starting to get it :D However, I am not talking about data not-being available - but how to effectively use APNS with the server informing the client of new data and the client ACTUALLY 100% getting it.Boyish
"If the app is in the foreground and there is new data on the server, but the polling request for new data fails, how would the client know to get the new data?" -> "If the app is in the foreground and there is new data on the server, and the push-notification fails to get delivered, how would the client know to get the new data?" this is what I meant, am I missing something here ? I am trying to find an answer regardless of the implementation, but in my particular instance I am talking about a small set of data updated few times a day.Boyish
All I'm saying is that you cannot guarantee delivery through any mechanism since the network is not perfect. All you can do is try again later; when that "later" is (viewWillAppear:, coming to foreground, etc) is up to you. If APNS fails to deliver your notification, you will find out there's new data on your next polling attempt. So, you must poll at some point; you can just do it less frequently with APNS because it usually delivers things quickly and reliably.Gyatt
1. Please correct me if I'm wrong: So you're basically saying whenever your app is brought to foreground or for any viewController that is appeared again: Do another network call to make sure you have the latest. 2. What mechanism should you follow to download the minimum amount required? I mean you don't want to download the data unless you know there's new data. I've heard of a HEAD http request. Which uses the same URL a GET request would use, but it first checks if the latest was queried before and if it was then it would just return idk return empty?!! (1/2)Gabbie
But also heard that HEAD requires some server side configuration. 3. Additionally how are you going to differentiate between different parts of your app calling the same endpoint. How would know which part of your app has the latest or not. I mean technically viewController3 could make a HEAD request for URLXYZ, but also viewController* could make the same URLXYZ request or is that you should attach an identifier to your urls to differentiate who's calling?! or maybe route all your network calls to a single manager which would then resolve the issue. (2/2)Gabbie
@Honey you should probably ask a new question about this, since the topic of how to efficiently poll for new data is complex and not well-suited for a couple comments. If you do ask a new question, please post a link here.Gyatt
sure will do. Can you address the first note?Gabbie
The answer is: it depends. I would definitely check for new data when coming to he foreground but whether you should also check on viewDidAppear or similar is really up to how frequently your data changes, how much data is shared between views, etc. You might even consider something like: check on viewDidAppear but only if at least 2 minutes have passed.Gyatt
I created this question here. I would appreciate if you can share your thoughtsGabbie
R
0

It all depends on how you are planning on using APNS.

Lets say you were making an App that sold items like eBay. You have:
- bids being placed by multiple users
- countdown to item closing time

You would not use APNS to update the timer on the persons device or notify them of the current price of the item. These are too crucial to rely on a best-effort delivery and was not the intended use of APNS.

It would be best if, in this scenario, you had the app poll the server every X seconds for updated information. You could then user APNS for non-crucial features like notifying the user if they are outbid or if they have won the item.

Roentgenology answered 10/10, 2014 at 16:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.