Defining a Custom Sync Down Target
You define custom targets for sync down operations by subclassing your platform’s abstract base class for sync down targets. To use custom targets in hybrid apps, implement a custom native target class for each platform you support. The base sync down target classes are:
-
iOS:
Swift Objective-C SyncDownTarget SFSyncDownTarget - Android: SyncDownTarget
Required Methods
Every custom target class must implement the following required methods.
- Start Fetch Method
- Called by the sync manager to initiate the sync down operation. If maxTimeStamp is greater than 0, this operation becomes a
“resync”. It then returns only the records that have been created or updated since the
specified time.
- iOS:
-
- Swift
-
1func startFetch(syncManager: SyncManager, 2 maxTimeStamp: Int64, 3 errorBlock: SyncDownErrorBlock, 4 complete: SyncDownCompleteBlock) - Objective-C
-
1- (void) startFetch:(SFMobileSyncSyncManager*)syncManager 2 maxTimeStamp:(long long)maxTimeStamp 3 errorBlock:(SFSyncDownTargetFetchErrorBlock) 4 errorBlock 5 completeBlock:(SFSyncDownTargetFetchCompleteBlock) 6 completeBlock;
- Android:
- JSONArray startFetch(SyncManager syncManager, long maxTimeStamp);
- Continue Fetching Method
- Called by the sync manager repeatedly until the method returns null. This process retrieves
all records that require syncing.
- iOS:
-
- Swift
-
1func continueFetch(syncManager: SyncManager, 2 onFail: SyncDownErrorBlock, 3 onComplete: SyncDownCompletionBlock?) - Objective-C
-
1- (void) 2 continueFetch:(SFMobileSyncSyncManager*)syncManager 3 errorBlock:(SFSyncDownTargetFetchErrorBlock) 4 errorBlock 5 completeBlock:(SFSyncDownTargetFetchCompleteBlock) 6 completeBlock;
- Android:
- JSONArray continueFetch(SyncManager syncManager);
- modificationDateFieldName Property (Optional)
-
Optionally, you can override the modificationDateFieldName property in your custom class. If you provide modificationDateFieldName, Mobile Sync uses the field with this name to compute the maxTimestamp value that startFetch uses to resync the records. Default field name is lastModifiedDate.
- iOS (Swift and Objective-C):
- modificationDateFieldName property
- Android:
- String getModificationDateFieldName();
- idFieldName Property (Optional)
-
If you provide "idFieldName", Mobile Sync uses the field with the given name to get the ID of the record. For example, if you specify "idFieldName":"AcmeId", Mobile Sync obtains the record’s ID from the AcmeId field instead of the default Id field.
- iOS (Swift and Objective-C):
- idFieldName property
- Android:
- String getIdFieldName();