0

I know how to check internet connection. Tell me how to sync app data.

How does the synchronization works when internet is available ?

My confusion :

I have app which uses the web-service to display data on iPhone and also on site. Now I can update user's work when the net is available by calling web-service at same time when user does some task.

But when internet is not available, I have to keep user's data locally(say SQLite) in iPhone and when the internet is reachable I have to update all the data on server.

For Example, 

      If internet is reachable, user works on some task and I update the data on server at the dame time.

      But Now internet is not reachable, user works on `N task`. I can not update on server, I have to wait for internet 
      How can I update all task on web-server at time?

So my question is :

How can I update all the data when net is available ?

Any link or code which can help me ?

Devang
  • 10,938
  • 13
  • 60
  • 96

3 Answers3

3

Try to put a Field as isOfflinerecord in your database (In case If you are using Database) and when connectivity comes back update or Insert only those data. This could be your initial step.

Heena
  • 2,318
  • 3
  • 30
  • 55
1

use reachability class and then you can set a notifier that will notify when there will be a change of the network status

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

hostReachable = [[Reachability reachabilityWithHostName: @"www.google.com"] retain];
[hostReachable startNotifier];


- (void) checkNetworkStatus:(NSNotification *)notice
{
    // called after network status changes

    NetworkStatus hostStatus = [hostReachable currentReachabilityStatus];
    switch (hostStatus)

{
    case NotReachable:
    {
        break;

    }
    case ReachableViaWiFi:
    {

        break;

    }
    case ReachableViaWWAN:
    {

        break;
    }
}

}
DShah
  • 9,510
  • 10
  • 66
  • 123
user784625
  • 1,838
  • 5
  • 24
  • 38
  • I know how to check internet connection. Tell me something about syncing data. – Devang Feb 02 '12 at 14:24
  • run the web service you have multiple times? – user784625 Feb 02 '12 at 14:38
  • 1
    @Devang How you sync the data will depend on your server and what you are transmitting. It is entirely up to you how you do this and if you ask 10 developers, you will probably get 10 different solutions. I suggest you go and think about it and come up with your own solution as this is quite a broad question to ask. – Nick Bull Feb 02 '12 at 15:41
  • @NickBull : I dont have any basic knowledge. I am just asking for basic knowledge. – Devang Feb 02 '12 at 16:19
  • @Devang Seriously, if you don't have any idea where to start with this, then I think you need to start learning some more basics of programming – Nick Bull Feb 02 '12 at 21:40
1

This question might be able to help you. using the Reachability class from Apple.

` How to check for an active Internet connection on iOS or OSX?

Community
  • 1
  • 1
Amit Shah
  • 4,127
  • 2
  • 19
  • 26
  • I know how to check internet connection. Tell me something about syncing data – Devang Feb 02 '12 at 14:24
  • Well, the way to do that would be to make a request to the server every so often when there is internet, and download the latest updates, and save them locally. Depending on the size of your online database you could just download it all at once. – Amit Shah Feb 02 '12 at 14:27
  • oh !! and how to upload app data on server ? – Devang Feb 02 '12 at 14:28
  • Depending on how your server is set up, you would just send a `POST` request containing the data. Using NSURLConnection is the simplest HTTP library to use, but there are others. – Amit Shah Feb 02 '12 at 14:30
  • @Devang so you want a SQLLite crash course AND a webservices crash course? – AnthonyBlake Feb 02 '12 at 15:01