0

I have an app which, from the app delegate, calls a synchronization engine. The synchronization engine fetches data from the web from a web service parses it and puts it in a core data base.

The individual you controllers call a fetch to the core database in order to present the data.

I want to add the feature of checking for Internet connectivity. Should I check for Internet connectivity in the app delegate and if there is one call the sync engine, else if there is not... What do I do, just leave it empty?

If (Internet) {
//call sync engine
} else { 
//do nothing
}
marciokoko
  • 4,988
  • 8
  • 51
  • 91

2 Answers2

1

To check for connectivity, there are a couple of options:

  1. Use Apple's Reachability class. Easy to use, simple but isn't ARC compatible.
  2. Use a 3rd party class that replaces Apple's. This one is good. ARC compatible.
LJ Wilson
  • 14,445
  • 5
  • 38
  • 62
  • Yes I am using reachability. But my question is how to handle using the local file instead of the web fetched file. – marciokoko Mar 06 '13 at 02:20
  • If you have structured both your local and web fetched file the same, you just need to put a conditional check for "Reachability". And then you can populate your model objects from that file. – Anupdas Mar 06 '13 at 02:28
0

Have you tried reachability? It works something like this:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(networkChanged:) name:kReachabilityChangedNotification object:nil];

online = [Reachability reachabilityForInternetConnection];
[online startNotifier];

- (void)networkChanged:(NSNotification *)notification {

  NetworkStatus remoteHostStatus = [online currentReachabilityStatus];

  if(remoteHostStatus == NotReachable) { 
      //use local file
  }
  else if (remoteHostStatus == ReachableViaWiFiNetwork) { 
      //use remote file
  }
  else if (remoteHostStatus == ReachableViaCarrierDataNetwork) { 
      //use remote file
  }
}
wigging
  • 8,492
  • 12
  • 75
  • 117
  • Yes I am using reachability. But my question is how to handle using the local file instead of the web fetched file. – marciokoko Mar 06 '13 at 02:20
  • @marciokoko See the edited answer above. Just use the local file when you are not connected to the internet. – wigging Mar 06 '13 at 04:14