0

I am working on an iOS/iphone app where I want users to actually have internet for the app to work.

I have some data fetched from the internet, so the app won't work as expected if the user is not connected.

I have many views, where I want to integrate a solution for this.

I thought of many ways to solve that, but I am not sure if there's a better 1.

  1. Adding check for internet in the app delegate, didfinihlanchingwithoptions. Issue -> the check will only happens when the user 1st open the application and not when he returns after a call for example, and will only happen on the rootviewcontroller.

  2. Adding the check in viewwillappear of each view. This works, and I put the checks in a way that the view won't block during trying to connect. But, what if the view was loaded, and then the user got disconnected.

Should I implement an NSTimer that keeps checking for internet? If yes, won't this be too heavy on the app? If No, what should I do?

Thank you.

1 Answers1

0

following link explains everything what you need to know for checking the internet availability, Reachability is provided by Apple with the sample code, You basically don't have to do much for checking the internet availability, just see the sample code provided by the apple and you will get what you are looking for. here is the link http://developer.apple.com/library/ios/#samplecode/Reachability/Introduction/Intro.html

nsgulliver
  • 12,655
  • 23
  • 43
  • 64
  • Yes, I know how to check for internet, but what I am asking is how to force the app to only work when the iphone is actually connected to the internet. Should I make a NSTimer selector that keeps checking for the internet? or is there a better solution? – user1731068 Jan 31 '13 at 14:45
  • You can disable multitasking by adding UIApplicationExitsOnSuspend to your info.plist and set it to true. when internet is not available , via Reachability you can show popup dialogue and this way you can achieve what you are looking for – nsgulliver Jan 31 '13 at 14:59
  • you could use `exit(0)` also but it is not a recommended approach, check out following link, it might help your cause also [link](http://stackoverflow.com/questions/355168/proper-way-to-exit-iphone-application) – nsgulliver Jan 31 '13 at 15:02