Search code examples
iosafnetworkingnsurlconnection

How should a follow "queue" on iOS with AFNetworking/NSURLConnection


I have the following implementation in my app:
- A list of topics to follow using their ids.
- A system which retries connections when they fail due to internet dropping/server failure.

Let's say a user taps 3 follow buttons very fast.
For each of the taps a NSURLConnection is started to assign to that user that topic How should this be approached considering the following cases that might occur:

A) All 3 connections fail. All 3 need to be retried, but each has a different parameter - the topic id. B) Only 2 of the connections fail, the third one succeeds.
C) The first connection fails, but after the user pressed the unfollow button which also fails.

By fail, in this case I mean that a pop-up appears which prompts the user to retry.
This happened because the NSURLConnection received a 404 or timed out.


Solution

  • As a rule, you shouldn't make the user dismiss a popup when a connection fails, but rather should show some indicator in the UI. After all, there's usually nothing the user can do to fix the connection, and the user wouldn't have asked for the data if he/she didn't want it, so silently retrying as soon as the network comes back is almost invariably the right behavior, making the user's action superfluous.

    In every case, start watching for reachability changes, then try again when reachability says that the request might succeed.