0

I have a app from where i hit different REST urls. one of the service is login service. Now, do i have to use the apple rechability test everytime i want to make a connection? I use ASIHttpRequest

hburkule
  • 49
  • 6

3 Answers3

2

No, ASIHTTPRequest will return a timeout error / a connection failure error if it can't reach the host. You can use those errors to show something to the user to tell them their login has failed.

deanWombourne
  • 38,189
  • 13
  • 98
  • 110
  • Okay. So, ASIHttpRequest will use Rechability internally? The reason I am asking is that ive heard that Apple will reject apps that don't conform to Rechability for testing the connection. – hburkule Jun 09 '11 at 15:28
  • ASI does use reachability for some things but I don't know exactly what. However, Apple never refuse apps for not using Reachability specifically - as long as you make it clear to the user what's going on then they will be fine with whatever method used to detect that there is no connection. I've certainly submitted (and had accepted) apps that only use ASIHTTPRequest :) – deanWombourne Jun 09 '11 at 16:57
0

The connectivity status of your mobile device can change very often and unforeseeably, so checking it often is advisable.

Say, for example, that you check at app startup, and find that not network is available. You go to offline mode, but then in a few minutes you could get in a WI-FI area or your 3G signal might be stronger. If you don't check it again, you lose the possibility of going to online mode.

Indeed, checking for network availability is pretty fast compared to how long a network request lasts (say: sending a login request and waiting for the response), so you can safely do the check whenever you need it according to your policy, be it at each request, every 5 minutes, or whatever.

EDIT:

about your concern as to the approval process: you should ensure that your app has a reasonable behavior when no connection it available. Simply showing an alert to the user (and not crashing) is enough for Apple, but you could also resort to disabling all your network related buttons, or whatever fits your app. The idea is that your app should not behave crazily when no connection is available.

If you want more advanced behavior, you can check reachability with each request.

You can also use the Reachability notification service (ASIHTTP-bundled Reachability includes that feature). You can find an how-to here. But in my opinion is a bit easier to just do the check when you need it. YMMV

Community
  • 1
  • 1
sergio
  • 68,819
  • 11
  • 102
  • 123
  • Okay. Lets say, I have a offline mode where i show some data already stored on the device, Then in that case i wouldn't want to show alert messages everytime. In this case can i use Rechability to inform me about availabilty of connection so that i can then show a alert and ask user to login? – hburkule Jun 09 '11 at 15:32
0

From what I remember the reachability demo code is effectively a listener so can update a variable as the device's reachability state changes. You then need to check this variable before making a request. Would be surprised ASIHTTP doesn't do this kind of thing already.

AlexJReid
  • 1,601
  • 1
  • 13
  • 17
  • That would be interesting. Checking a variable modified by a listener would be a good way i believe. Not aware of ASIHttpRequest having such a thing. Will have to check. – hburkule Jun 09 '11 at 15:30