nothirst / TICoreDataSync

Automatic synchronization for Core Data apps, between any combination of Mac OS X and iOS: Mac to iPhone to iPad to iPod touch and back again.
https://github.com/nothirst/TICoreDataSync/wiki
807 stars 61 forks source link

documentSyncManagerDidFinishSynchronizing executed 2 times #94

Closed pventura1976 closed 10 years ago

pventura1976 commented 10 years ago

Hi all,

Is it normal that documentSyncManagerDidFinishSynchronizing: executes two times?

What I'm trying to do is to show up a message when the background sync is done. Is there a property that I should read to control exactly when the sync has finished?

Regards, Pedro

renzos commented 10 years ago

In order to detect the sync has finished just put this delegate method in your AppDelegate.m:

- (void)documentSyncManagerDidFinishSynchronizing:(TICDSDocumentSyncManager *)aSyncManager{
    NSLog(@"%@", @"SYNC FINISHED");
    //DO WHATEVER YOU WANT HERE
}
pventura1976 commented 10 years ago

Yep, that's just what I did, but I don't know why this method is being called twice!

2014-03-17 15:45:44.080 FlexList[16223:60b] documentSyncManagerDidFinishSynchronizing
2014-03-17 15:45:47.459 FlexList[16223:60b] documentSyncManagerDidFinishSynchronizing
renzos commented 10 years ago

I tried just now with my app and it's called once for every synchronization. Very strange...in your app it seems that the delegate it's called twice.

pventura1976 commented 10 years ago

So I'm doing something wrong. I'll debug a little bit more and post the results. Thanks Renzos for the answer :)

renzos commented 10 years ago

Let us know, in the meantime I'm facing a new strange issue I published an hour ago.

pventura1976 commented 10 years ago

I've found why the App is firing sync process twice. This is due to two reasons:

1.- I'm firing one of them manually:

- (void)documentSyncManagerDidFinishRegistering:(TICDSDocumentSyncManager *)aSyncManager
{
    if (self.shouldDownloadStoreAfterRegistering)
    {   
        [aSyncManager initiateDownloadOfWholeStore];
    }
    else
    {   
        [aSyncManager initiateSynchronization];
    }   
    [aSyncManager beginPollingRemoteStorageForChanges];
}

2.- The 2nd is because TICDS is always finding changes as the app starts; and this is because I'm firing a vacuum process at the start that always has something to fix... :-(

So this is normal. Closing.