1

I have an app. In this app, a user can like/unlike something. If the user tap the button like, it would change text to unlike, vice versa.

To make the like/unlike event run seamlessly to user, i change the text first, and then make request to my API, saying that the user like/unlike this. The API decides whether the action is liking or unliking depends on value at database. The API then returns a message stating the action made ("liked"/"unliked"). The app receives it, and then update the UI according to the result, in case the action intended by user fails.

If all runs smoothly, the user won't detect the changes made by API result.

This is the flow of liking something

user like -> button text changes to "unlike" 
-> app make a request -> request is queued to operation queue
-> request run -> API decides whether that something is liked/unliked by the user
-> API returns action (in this case, "liked") -> app updates button text ("unlike")

Now my question are:

  1. How do I handle rapid button tap by user?
  2. How do I handle failed requests (internet disconnected, or no signal) while handling the problem no. 1?

nb: I don't want to disable the button (the app has to run seamlessly. Facebook app don't do it either, i just checked). Oh, and I use AFHTTPRequestOperationManager and set its maxConcurrentOperationCount to 1.

Oscar Yuandinata
  • 1,025
  • 1
  • 13
  • 31
  • Usually that kind of API's response time is very short. If you setUserInteraction:NO to the like button while API's running, no user can realize that the button is not activated. If you do so, 2 is not a problem. – Ryan Jul 03 '14 at 07:47
  • At my country, fast internet is a luxury. LOL. One can expect at most 1 second delay with 3G. Surely it would be realized by the user, yes? I just tried Facebook app and they don't disable the button either – Oscar Yuandinata Jul 03 '14 at 07:51
  • Well, If user touched while API is running, just cancel the previous request and set the UI back. – Ryan Jul 03 '14 at 07:57
  • thx, but tracking the request is a difficult job. I end up using [link](http://stackoverflow.com/a/18102576/1249118) here. Anyway, thx – Oscar Yuandinata Jul 03 '14 at 08:47

1 Answers1

0

I resolved my problem using this answer

with a bit modification. The first time user click the button, I set a request flag to false, so that even if the user click the button many times, request won't be made before the first request is done.

Community
  • 1
  • 1
Oscar Yuandinata
  • 1,025
  • 1
  • 13
  • 31