Conforms to | |
Framework | /System/Library/Frameworks/SyncServices.framework |
Availability | Available in Mac OS X v10.5 and later. |
Companion guide | |
Declared in | ISyncCoreData.h |
The NSPersistentStoreCoordinatorSyncing
protocol defines callback messages that are sent to a sync handler while a Core Data application syncs. You set a sync handler when you start a sync session using the syncWithClient:inBackground:handler:error:
NSPersistentStoreCoordinator
method. The callback messages defined in this protocol are sent before and after most phases of a sync session. A sync handler may implement these optional methods to customize the behavior of sync sessions. For example, a sync handler might change records before their pushed to the sync engine or verify changes pulled from the sync engine before they are applied to managed objects.
Read Syncing Core Data Applications in Sync Services Programming Guide for more details on using Core Data sync.
– managedObjectContextsToMonitorWhenSyncingPersistentStoreCoordinator:
– managedObjectContextsToReloadAfterSyncingPersistentStoreCoordinator:
– persistentStoreCoordinatorShouldStartSyncing:
– persistentStoreCoordinator:willPushChangesInSyncSession:
– persistentStoreCoordinator:didPushChangesInSyncSession:
– persistentStoreCoordinator:willPullChangesInSyncSession:
– persistentStoreCoordinator:didPullChangesInSyncSession:
– persistentStoreCoordinator:didFinishSyncSession:
– persistentStoreCoordinator:didCancelSyncSession:error:
– persistentStoreCoordinator:willPushRecord:forManagedObject:inSyncSession:
– persistentStoreCoordinator:willDeleteRecordWithIdentifier:inSyncSession:
– persistentStoreCoordinator:willApplyChange:toManagedObject:inSyncSession:
– persistentStoreCoordinator:didApplyChange:toManagedObject:inSyncSession:
– persistentStoreCoordinator:didCommitChanges:inSyncSession:
Returns the managed object contexts that the receiver wants to monitor during the next sync session.
- (NSArray *)managedObjectContextsToMonitorWhenSyncingPersistentStoreCoordinator:(NSPersistentStoreCoordinator *)coordinator
The persistent store coordinator being synced.
An array containing the managed object contexts to monitor.
The sync session uses this method to determine if pulled changes should be applied. Pulled changes are ignored—not applied to a record—if any of the managed contexts, returned by this method, changed the same record. In this case, the local changes are pushed in the next sync session and the sync engine is responsible for resolving any conflicts.
Conflicts can result if clients are allowed to change managed objects during a sync session or editing is not disabled during syncing. For example, conflicts can result if the user changes a managed object while the sync session is pulling changes to the same managed object. However, implementing this method does not handle all types of conflicts. The user may still modify a managed object after a sync session applies changes and before a sync session finishes. To avoid this, you should either not allow editing during a sync session, or be prepared to merge local changes with pulled changes after a sync session.
Therefore, although this method is optional, not implementing this method increases the risk of conflicts unless you sync synchronously or disable editing when syncing.
ISyncCoreData.h
Returns the managed object contexts that should be reloaded after the persistent store coordinator syncs.
- (NSArray *)managedObjectContextsToReloadAfterSyncingPersistentStoreCoordinator:(NSPersistentStoreCoordinator *)coordinator
The persistent store coordinator being synced.
An array containing the managed object contexts to reload.
If you do not implement this method, it is your responsibility to reload managed object contexts after a sync.
ISyncCoreData.h
Informs the receiver that pulled changes were applied to a specific record during a sync session.
- (void)persistentStoreCoordinator:(NSPersistentStoreCoordinator *)coordinator didApplyChange:(ISyncChange *)change toManagedObject:(NSManagedObject *)managedObject inSyncSession:(ISyncSession *)session
The persistent store coordinator being synced.
The changes that was applied.
The managed object that corresponds to the changes.
The sync session that applied the changes.
ISyncCoreData.h
Informs the receiver that a session was cancelled.
- (void)persistentStoreCoordinator:(NSPersistentStoreCoordinator *)coordinator didCancelSyncSession:(ISyncSession *)session error:(NSError *)error
The persistent store coordinator being synced.
The sync session that was cancelled.
Describes the error that caused the cancellation.
ISyncCoreData.h
Informs the receiver that all applied changes were committed during a sync session.
- (void)persistentStoreCoordinator:(NSPersistentStoreCoordinator *)coordinator didCommitChanges:(NSDictionary *)changes inSyncSession:(ISyncSession *)session
The persistent store coordinator being synced.
A dictionary containing the changes to possibly multiple objects that were applied and committed. The dictionary contains the following keys: NSInsertedObjectsKey
, NSUpdatedObjectsKey
, and NSDeletedObjectsKey
.
The sync session that committed the changes.
Typically, this method is invoked after the persistent store changes are saved and the sync session receives the clientCommittedAcceptedChanges
message. This method can be invoked multiple times during a sync session.
ISyncCoreData.h
Informs the receiver that a session was finished.
- (void)persistentStoreCoordinator:(NSPersistentStoreCoordinator *)coordinator didFinishSyncSession:(ISyncSession *)session
The persistent store coordinator being synced.
The sync session that finished.
ISyncCoreData.h
Informs the receiver that changes were pulled from the sync engine.
- (void)persistentStoreCoordinator:(NSPersistentStoreCoordinator *)coordinator didPullChangesInSyncSession:(ISyncSession *)session
The persistent store coordinator being synced.
The sync session that pulled the changes.
ISyncCoreData.h
Informs the receiver that client changes were pushed to the sync engine.
- (void)persistentStoreCoordinator:(NSPersistentStoreCoordinator *)coordinator didPushChangesInSyncSession:(ISyncSession *)session
The persistent store coordinator being synced.
The sync session that pushed the changes.
ISyncCoreData.h
Informs the receiver that pulled changes will be applied to a specific record during a sync session.
- (ISyncChange *)persistentStoreCoordinator:(NSPersistentStoreCoordinator *)coordinator willApplyChange:(ISyncChange *)change toManagedObject:(NSManagedObject *)managedObject inSyncSession:(ISyncSession *)session
The persistent store coordinator being synced.
The changes that will be applied. An ISyncChange
object can represent a delete record change, as well as an insert and update record change.
The managed object that corresponds to the changes.
The sync session that is applying the changes.
The change to apply. nil
if you do not want to apply this change.
Implement this method if you want to modify a change before it is applied.
ISyncCoreData.h
Informs the receiver that a specific record will be deleted during the pushing phase of a sync session.
- (BOOL)persistentStoreCoordinator:(NSPersistentStoreCoordinator *)coordinator willDeleteRecordWithIdentifier:(NSString *)identifier inSyncSession:(ISyncSession *)session
The persistent store coordinator being synced.
The identifier for the record that will be deleted.
The sync session that is pushing records.
YES
to delete the record; otherwise, NO
.
Implement this method if you want to verify if a record should be deleted before it is deleted.
ISyncCoreData.h
Informs the receiver that changes will be pulled from the sync engine.
- (void)persistentStoreCoordinator:(NSPersistentStoreCoordinator *)coordinator willPullChangesInSyncSession:(ISyncSession *)session
The persistent store coordinator being synced.
The sync session that is pulling the changes.
ISyncCoreData.h
Informs the receiver that client changes will be pushed to the sync engine.
- (void)persistentStoreCoordinator:(NSPersistentStoreCoordinator *)coordinator willPushChangesInSyncSession:(ISyncSession *)session
The persistent store coordinator being synced.
The sync session that is pushing the changes.
ISyncCoreData.h
Informs the receiver that client changes to a specific record will be pushed to the sync engine.
- (NSDictionary *)persistentStoreCoordinator:(NSPersistentStoreCoordinator *)coordinator willPushRecord:(NSDictionary *)record forManagedObject:(NSManagedObject *)managedObject inSyncSession:(ISyncSession *)session
The persistent store coordinator being synced.
The record that will be pushed.
The managed object that corresponds to the record.
The sync session that is pushing records.
The record to push. nil
if you do not want to push the record.
Implement this method if you want to modify a record before pushing it.
ISyncCoreData.h
Returns whether or not the persistent store coordinator should start syncing.
- (BOOL)persistentStoreCoordinatorShouldStartSyncing:(NSPersistentStoreCoordinator *)coordinator
The persistent store coordinator being synced.
YES
if the persistent store coordinator can start syncing; otherwise, NO
.
ISyncCoreData.h
© 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-07-11)