Home > Articles > Home & Office Computing > Mac OS X

  • Print
  • + Share This
Like this article? We recommend

Like this article? We recommend

Pushing Your Data

In my fictional application, I put all the actual sync code into one method, which enables one method to handle all three types of sync routines (sync request from another application, foreground sync, and background sync). The signature of this method is as follows:

- (void)clientSync:(ISyncClient *)client session:(ISyncSession *)sess;

The client being the ISyncClient the application received back from the ISyncManager, and the session being the ISyncSession reference provided during the sync request.

The first phase of a sync session involves pushing the application’s changes to the truth database. There are two types of push at this point: a slow push and a fast push. A slow push involves pushing all the data that the application has to the truth database, and a fast push involves pushing only the changes made to the data since the last push. To determine which type of push is needed, the application needs to ask the session:

NSEnumerator *entityEnumerator;
NSString *entityName;
NSMutableArray *filtered = [NSMutableArray array];

entityEnumerator = [[client enabledEntityNames] objectEnumerator];
while (entityname = [entityEnumerator nextObject]) {
 if (![sess shouldPushChangesForEntityName:entityName]) {
  continue;
 }
 [filtered addObject:entityName];
 if ([sess shouldPushAllRecordsForEntityName:entityName]) {
  [self slowSync:entityName session:sess];
 } else {
  [self fastSync:entityName session:sess];
 }
}

In this part of the sync session, I first get an array of all the enabled entities. I then walk though those entities, asking the session whether the entity should be skipped and then whether the truth database wants all that data type or just the changes. During this loop, I also keep track of which objects the truth database wants updates on for the next phase in the session.

  • + Share This
  • 🔖 Save To Your Account