Beginning a Sync Session
Once the client has been registered with the truth database, it is time to begin a sync session. Sync sessions can be initiated by an application, either in the foreground or in the background. When a session is initiated in the foreground, the application (or the current thread) halts until the sync engine is ready for the session to begin. If it is initiated in the background, the client will be notified at a later time when the session is to begin.
To initiate a session in the foreground:
ISyncSession *session = [ISyncSession beginSessionWithClient:client entityNames:entityNames beforeDate:[NSDate dateWithTimeIntervalSinceNow:5]];
And to initiate it in the background:
[ISyncSession beginSessionInBackgroundWithClient:syncClient entityNames:[syncClient supportedEntityNames] target:self sel\ector:@selector(clientSync:session:)];
This will cause the ISyncManager to call the selected method once the session is ready. In either case, the actual sync session is the same. As mentioned in the previous article, the session goes through three phases: Push, Mingle, and then Pull.
The entityNames reference is an NSArray of the names of the entities to be synced in this session. Normally, they are all the names in your client description file. The NSDate in the foreground method call tells the ISyncManager how long the application is willing to wait for the session to begin. This gives other applications a time limit for joining the session and prevents other applications from causing your session to halt. The selector defined in the background call defines the method that is to be called when the session is ready to begin.