WHISyncController Class Reference
| Inherits from | NSObject |
| Declared in | WHISyncController.h |
Overview
The WHISyncController class is the main entry point for starting and interfacing with the Wasabi Sync subsystem. Currently this is a singleton, but you should not rely on this behavior as this is likely to change in future releases.
To begin synchronizing data, You should first initialize the system by using the globalInstanceWithServerURL:contextCreator: class method. This should be done early in your application launch cycle. You should also set the appId and apiKey. You get these values from the Wasabi Sync web portal. The synchronization system will not begin actually actively syncing objects until you call the start method. A typical initialization would look something like the following:
WHISyncController *sync = [WHISyncController globalInstanceWithServerURL:@"http://www.wasabisync.com/"
contextCreator:^NSManagedObjectContext *
{
return {... code to create new NSManagedObjectContexts for your app ...} ;
}];
[sync setAppId:@"com.yourcompany.yourapp"];
[sync setApiKey:@"yourkey"];
[sync load];
[sync start];
The call to load loads the synchronization state, if any, that was previously saved using a call to save. This allows any transactions which are currently in progress to saved to disk so that they can be continued later.
The purpose of the context creator block is to give the synchronization system a mechanism for creating new NSManagedObjectContexts as needed. The synchronization system uses background threads in some operations. In these cases, it needs to be able to create new contexts that can be used with these threads. Therefore, it is very important that the context returned from this block is not your main thread context. It is generally preferred that the code used here returns a new context whenever this block is executed.
Tasks
Other Methods
-
refreshIntervalThe time in seconds between polling calls to the server. Default is every 60 seconds. This may change under heavy server load.
property -
lastSyncThe last time they synchronization successfully completed.
property -
lastErrorThe last error that occurred when contacting the server.
property -
latestModelVersionThe current model version.
property -
syncInProgressTrue when a sync is currently in progress.
property -
enableChunkingEnables sending large datasets in chunks.
property -
serverUrlThe URL of the server to send data to.
property -
emailAddressThe user’s email address.
property -
userPasswordThe user’s password.
property -
appIdThe application id.
property -
apiKeyThe API key for this application.
property -
logErrorsToConsoleEnables logging of errors to the console. Might be helpful for debugging.
property
Initialization
-
+ globalInstanceClass singleton accessor
-
+ globalInstanceWithServerURL:contextCreator:Initialization factory method.
-
– resetTimerResets the refresh timer.
Change observation
-
– disableObservingDisable observation of changes. If you disable observing and then change your synchronized objects, those changes will not synchronize.
-
– enableObservingEnable observation of changes. If you call
disableObservingyou must remember to call this method to re-enable observation.
Login and Logout
-
– loginWithEmailAddress:password:callback:Logs the user in using the give email address and password.
-
– logoutLogs the user out of the server and disables synchronization.
-
– logoutWithCallback:Logs the user out of the server and disables synchronization.
-
– signupWithEmailAddress:password:callback:Creates an account on the server for the given username and password.
-
– loggedInReturns TRUE if the user is currently logged into the server.
Synchronization Control
-
– startStart automatically synchronizing with the server.
-
– cancelStops automatic synchronization with the server.
-
– forceSyncForces a synchronization right now.
-
– forceSyncWithContinuation:Forces a synchronization with the server with a continuation.
Saving and Restoring State
Properties
apiKey
The API key for this application.
@property (strong, nonatomic) NSString *apiKeyDiscussion
The API key for this application.
Declared In
WHISyncController.happId
The application id.
@property (strong, nonatomic) NSString *appIdDiscussion
The application id.
Declared In
WHISyncController.hemailAddress
The user’s email address.
@property (strong, nonatomic) NSString *emailAddressDiscussion
The user’s email address.
Declared In
WHISyncController.henableChunking
Enables sending large datasets in chunks.
@property (nonatomic) BOOL enableChunkingDiscussion
Enables sending large datasets in chunks.
Large datasets can take time to parse on the server. If you’re sending large datasets, you should enable this flag to improve performance on the server.
Declared In
WHISyncController.hlastError
The last error that occurred when contacting the server.
@property (strong) NSError *lastErrorDiscussion
The last error that occurred when contacting the server.
Declared In
WHISyncController.hlastSync
The last time they synchronization successfully completed.
@property (strong) NSDate *lastSyncDiscussion
The last time they synchronization successfully completed.
Declared In
WHISyncController.hlatestModelVersion
The current model version.
@property (strong, nonatomic) NSString *latestModelVersionDiscussion
The current model version.
Whenever you make significant changes to your schema that require a migration, you should probably increment your model version to prevent the user from attempting to synchronize two devices with different versions of the schema.
Declared In
WHISyncController.hlogErrorsToConsole
Enables logging of errors to the console. Might be helpful for debugging.
@property (nonatomic) BOOL logErrorsToConsoleDiscussion
Enables logging of errors to the console. Might be helpful for debugging.
Declared In
WHISyncController.hrefreshInterval
The time in seconds between polling calls to the server. Default is every 60 seconds. This may change under heavy server load.
@property (nonatomic) NSTimeInterval refreshIntervalDiscussion
The time in seconds between polling calls to the server. Default is every 60 seconds. This may change under heavy server load.
Declared In
WHISyncController.hserverUrl
The URL of the server to send data to.
@property (strong, nonatomic) NSString *serverUrlDiscussion
The URL of the server to send data to.
The default for this is http://www.wasabisync.com/. If you want to use ssl or an alternative server, you can change that here.
Declared In
WHISyncController.hClass Methods
Instance Methods
cancel
Stops automatic synchronization with the server.
- (void)cancelDiscussion
Stops automatic synchronization with the server.
Declared In
WHISyncController.hdisableObserving
Disable observation of changes. If you disable observing and then change your synchronized objects, those changes will not synchronize.
- (void)disableObservingDiscussion
Disable observation of changes. If you disable observing and then change your synchronized objects, those changes will not synchronize.
The process of serializing the objects that have been changed can be slow if you are doing a lot of inserts or deletions at once. In some rare cases, you may want to disable observation, do all your inserts and deletes, and then let the server ask for the changed objects. When you do this, the serialization will occur on a background thread and may be faster.
Declared In
WHISyncController.henableObserving
Enable observation of changes. If you call disableObserving you must remember to call this method to re-enable observation.
- (void)enableObservingDiscussion
Enable observation of changes. If you call disableObserving you must remember to call this method to re-enable observation.
You do not need to call this unless you have called disableObserving. Observation defaults to on unless you explicitly disable it.
Declared In
WHISyncController.hforceSync
Forces a synchronization right now.
- (void)forceSyncDiscussion
Forces a synchronization right now.
Declared In
WHISyncController.hforceSyncWithContinuation:
Forces a synchronization with the server with a continuation.
- (void)forceSyncWithContinuation:(void ( ^ ) ( void ))inContinuationParameters
- inContinuation
when the synchronization completes, the continuation will be called.
Discussion
Forces a synchronization with the server with a continuation.
Declared In
WHISyncController.hload
Loads transactions previously saved using save.
- (void)loadDiscussion
Loads transactions previously saved using save.
Declared In
WHISyncController.hloggedIn
Returns TRUE if the user is currently logged into the server.
- (BOOL)loggedInDiscussion
Returns TRUE if the user is currently logged into the server.
Declared In
WHISyncController.hloginWithEmailAddress:password:callback:
Logs the user in using the give email address and password.
- (void)loginWithEmailAddress:(NSString *)inEmailAddress password:(NSString *)inPassword callback:(void ( ^ ) ( BOOL succeeded , NSError *inError ))inCallbackParameters
- inEmailAddress
the email address of the user.
- inPassword
the password for the user.
- inCallback
Called when the operation has completed.
Discussion
Logs the user in using the give email address and password.
Declared In
WHISyncController.hlogout
Logs the user out of the server and disables synchronization.
- (void)logoutDiscussion
Logs the user out of the server and disables synchronization.
Declared In
WHISyncController.hlogoutWithCallback:
Logs the user out of the server and disables synchronization.
- (void)logoutWithCallback:(void ( ^ ) ( BOOL succeeded , NSError *inError ))inCallbackParameters
- inCallback
block callback is called when the operation completes.
Discussion
Logs the user out of the server and disables synchronization.
Declared In
WHISyncController.hresetTimer
Resets the refresh timer.
- (void)resetTimerDiscussion
Resets the refresh timer.
Declared In
WHISyncController.hsave
Saves the currently unsynced transactions to the server.
- (void)saveDiscussion
Saves the currently unsynced transactions to the server.
Declared In
WHISyncController.hsignupWithEmailAddress:password:callback:
Creates an account on the server for the given username and password.
- (void)signupWithEmailAddress:(NSString *)inEmailAddress password:(NSString *)inPassword callback:(void ( ^ ) ( BOOL succeeded , NSError *inError ))inCallbackParameters
- inEmailAddress
The email address of the user.
- inPassword
The user’s password. You are responsible for prompting the user to confirm their password before sending.
- inCallback
A block to call when the operation completes.
Discussion
Creates an account on the server for the given username and password.
Declared In
WHISyncController.h