OMCSynchronization Class Reference
Inherits from | OMCServiceProxy : NSObject |
---|---|
Declared in | OMCSynchronization.h |
Overview
The main class for the Synchronization service implementation. Contains methods to make requests and manipulate the local cache.
– initialize
Initializes an OMCSynchronization
object with the settings from the ‘synchronization’ node of OMC.plist
* This method OR initializeWithMobileObjectEntities: should be the first method called on the OMCSynchronization class
* As per periodicRefreshPolicy in the ‘synchronization’ node of OMC.plist, this method will check for expired resources in the cache to auto refresh in background.
* If periodicRefreshPolicy is not or set to none, this method will continue with the expired resources in cache for auto eviction based on eviction policy set for those resources.
- (void)initialize
Declared In
OMCSynchronization.h
– initializeWithMobileObjectEntities:
Initializes an OMCSynchronization
object with the settings from the ‘synchronization’ node of OMC.plist and creates database entities for your business model or mobile objects using provided custom classes.
* This method OR the initialize method should be the first method called on the OMCSynchronization class
* As per periodicRefreshPolicy in the ‘synchronization’ node of OMC.plist, this method will check for expired resources in the cache to auto refresh in the background.
* If periodicRefreshPolicy is not set or is set to none, this method will continue with the expired resources in the cache for auto eviction based on the eviction policy set for those resources.
* When calling this method again, or after initialize with the different custom classes (entities), this will purge the local cache and re-create a blank database with new custom classes/entities as the db schema.
- (void)initializeWithMobileObjectEntities:(NSArray *_Nullable)customEntities
Parameters
customEntities |
(optional) Array of custom classes derived from the OMCMobileObject class; use class properties as entity attributes for queries. Example array: [NSArray arrayWithObjects:[MyClass1 class], [MyClass2 class], … , nil] |
---|
Declared In
OMCSynchronization.h
– openEndpoint:apiName:endpointPath:
Returns an object that provides access to an endpoint in a custom code API.
- (OMCMobileEndpoint *)openEndpoint:(Class _Nullable)mobileClass apiName:(NSString *)apiName endpointPath:(NSString *)endpointPath
Parameters
mobileClass |
(optional) The custom mobile object (entity) class that the custom code API exposes. (the custom mobile object class must have been registered through initializeWithMobileObjectEntities: method. Or pass nil. ) |
---|---|
apiName |
The name of the custom code API. |
endpointPath |
The endpoint in the custom code API. |
Return Value
An MobileEndpoint object for accessing custom code.
Declared In
OMCSynchronization.h
– requestWithUri:method:syncPolicy:headers:data:onSuccess:onError:
- Request for any method; can go to server or cache, depending on policy settings.
- (void)requestWithUri:(NSString *)uri method:(SyncRequestMethod)method syncPolicy:(OMCSyncPolicy *_Nullable)policy headers:(NSDictionary *_Nullable)headers data:(NSData *_Nullable)data onSuccess:(OMCSyncSuccessBlock _Nullable)success onError:(OMCSyncErrorBlock _Nullable)error
Parameters
uri |
The URI to send the request to. |
---|---|
method |
RequestMethod value. |
policy |
(optional) SyncPolicy object which has all policy settings. |
headers |
(optional) NSDictionary for extra headers to support request. |
data |
(optional) NSData for http body data; can set |
success |
(optional) The block will be invoked on success of the request. |
error |
(optional) The block will be invoked on error of the request. |
Declared In
OMCSynchronization.h
– synchronizePinnedResources:
- Synchronize all pinned resources.
- (void)synchronizePinnedResources:(BOOL)background
Parameters
background |
boolean to specify for background mode sync. |
---|
Declared In
OMCSynchronization.h
– loadOfflineResourcesOnSuccess:onError:
- Returns a list of all MobileResource objects that were updated offline/locally, and not yet successfully synchronized with the server.
- (void)loadOfflineResourcesOnSuccess:(OMCSyncMobileResourceArray _Nullable)success onError:(OMCSyncErrorBlock _Nullable)error
Parameters
success |
(optional) The block will be invoked on success; contains NSArray of OMCMobileResource(s) objects. (Can also be OMCMobileObject/OMCMobileFile/CustomClass) |
---|---|
error |
(optional) The block will be invoked on error. |
Declared In
OMCSynchronization.h
– discardOfflineUpdatesOnError:
- Discards all offline/local edits only for all the resources that are not yet successfully synchronized with server.
- Persistent state of the resources will remain in cache as is.
- (void)discardOfflineUpdatesOnError:(OMCSyncErrorBlock _Nullable)error
Parameters
error |
(optional) The block will be invoked on error. |
---|
Declared In
OMCSynchronization.h
– offlineResourceSynchronized:
- Event that is raised after every offline resource is synchronized with the service.
- (void)offlineResourceSynchronized:(OMCSyncResourceChanged)synchronizedResource
Parameters
synchronizedResource |
The block, invoked for each resource that is finished synchronizing. Pass nil to be removed from callbacks. |
---|
Declared In
OMCSynchronization.h
– cachedResourceChanged:
- Event that is raised every time a cached resource is updated, either from new data from the service,
- from an online or offline write by the application, or on a delete.
- (void)cachedResourceChanged:(OMCSyncResourceChanged)changedResource
Parameters
changedResource |
The block invoked for each resource changed in the cache. Pass nil to be removed from callbacks. |
---|
Declared In
OMCSynchronization.h
– evictResource:onError:
- Evict (delete) the resource from the local cache.
- (void)evictResource:(NSString *)uri onError:(OMCSyncErrorBlock _Nullable)error
Parameters
uri |
The URI of the resource. |
---|---|
error |
(optional) The block will be invoked on error of the request. |
Declared In
OMCSynchronization.h
– cacheHitCount
Returns the number of cache hits.
- (int)cacheHitCount
Return Value
The number of cache hits.
Declared In
OMCSynchronization.h
– cacheMissCount
Returns the number of cache misses.
- (int)cacheMissCount
Return Value
The number of cache misses.
Declared In
OMCSynchronization.h
– setOfflineMode:
- Sets device to offline mode. Useful for testing
- Note that calling setOfflineMode:true has no effect when the device isn’t connected to the internet.
- (void)setOfflineMode:(BOOL)isOffline
Parameters
isOffline |
boolean to set offline mode |
---|
Declared In
OMCSynchronization.h
– getNetworkStatus
- Gets device network status that is currently being used by Synchronization.
- (SyncNetworkStatus)getNetworkStatus
Return Value
SyncNetworkStatus enum
Declared In
OMCSynchronization.h