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

Initialization

Change observation

  • – disableObserving

    Disable observation of changes. If you disable observing and then change your synchronized objects, those changes will not synchronize.

  • – enableObserving

    Enable observation of changes. If you call disableObserving you must remember to call this method to re-enable observation.

Login and Logout

Synchronization Control

Saving and Restoring State

  • – save

    Saves the currently unsynced transactions to the server.

  • – load

    Loads transactions previously saved using save.

Properties

apiKey

The API key for this application.

@property (strong, nonatomic) NSString *apiKey

Discussion

The API key for this application.

Declared In

WHISyncController.h

appId

The application id.

@property (strong, nonatomic) NSString *appId

Discussion

The application id.

Declared In

WHISyncController.h

emailAddress

The user’s email address.

@property (strong, nonatomic) NSString *emailAddress

Discussion

The user’s email address.

Declared In

WHISyncController.h

enableChunking

Enables sending large datasets in chunks.

@property (nonatomic) BOOL enableChunking

Discussion

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.h

lastError

The last error that occurred when contacting the server.

@property (strong) NSError *lastError

Discussion

The last error that occurred when contacting the server.

Declared In

WHISyncController.h

lastSync

The last time they synchronization successfully completed.

@property (strong) NSDate *lastSync

Discussion

The last time they synchronization successfully completed.

Declared In

WHISyncController.h

latestModelVersion

The current model version.

@property (strong, nonatomic) NSString *latestModelVersion

Discussion

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.h

logErrorsToConsole

Enables logging of errors to the console. Might be helpful for debugging.

@property (nonatomic) BOOL logErrorsToConsole

Discussion

Enables logging of errors to the console. Might be helpful for debugging.

Declared In

WHISyncController.h

refreshInterval

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 refreshInterval

Discussion

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.h

serverUrl

The URL of the server to send data to.

@property (strong, nonatomic) NSString *serverUrl

Discussion

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.h

syncInProgress

True when a sync is currently in progress.

@property (nonatomic) BOOL syncInProgress

Discussion

True when a sync is currently in progress.

Declared In

WHISyncController.h

userPassword

The user’s password.

@property (strong, nonatomic) NSString *userPassword

Discussion

The user’s password.

Declared In

WHISyncController.h

Class Methods

globalInstance

Class singleton accessor

+ (WHISyncController *)globalInstance

Discussion

Class singleton accessor

Declared In

WHISyncController.h

globalInstanceWithServerURL:contextCreator:

Initialization factory method.

+ (WHISyncController *)globalInstanceWithServerURL:(NSString *)inServerURL contextCreator:(NSManagedObjectContext *( ^ ) ( void ))inCtxCreator

Discussion

Initialization factory method.

Declared In

WHISyncController.h

Instance Methods

cancel

Stops automatic synchronization with the server.

- (void)cancel

Discussion

Stops automatic synchronization with the server.

Declared In

WHISyncController.h

disableObserving

Disable observation of changes. If you disable observing and then change your synchronized objects, those changes will not synchronize.

- (void)disableObserving

Discussion

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.h

enableObserving

Enable observation of changes. If you call disableObserving you must remember to call this method to re-enable observation.

- (void)enableObserving

Discussion

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.h

forceSync

Forces a synchronization right now.

- (void)forceSync

Discussion

Forces a synchronization right now.

Declared In

WHISyncController.h

forceSyncWithContinuation:

Forces a synchronization with the server with a continuation.

- (void)forceSyncWithContinuation:(void ( ^ ) ( void ))inContinuation

Parameters

inContinuation

when the synchronization completes, the continuation will be called.

Discussion

Forces a synchronization with the server with a continuation.

Declared In

WHISyncController.h

load

Loads transactions previously saved using save.

- (void)load

Discussion

Loads transactions previously saved using save.

Declared In

WHISyncController.h

loggedIn

Returns TRUE if the user is currently logged into the server.

- (BOOL)loggedIn

Discussion

Returns TRUE if the user is currently logged into the server.

Declared In

WHISyncController.h

loginWithEmailAddress: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 ))inCallback

Parameters

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.h

logout

Logs the user out of the server and disables synchronization.

- (void)logout

Discussion

Logs the user out of the server and disables synchronization.

Declared In

WHISyncController.h

logoutWithCallback:

Logs the user out of the server and disables synchronization.

- (void)logoutWithCallback:(void ( ^ ) ( BOOL succeeded , NSError *inError ))inCallback

Parameters

inCallback

block callback is called when the operation completes.

Discussion

Logs the user out of the server and disables synchronization.

Declared In

WHISyncController.h

resetTimer

Resets the refresh timer.

- (void)resetTimer

Discussion

Resets the refresh timer.

Declared In

WHISyncController.h

save

Saves the currently unsynced transactions to the server.

- (void)save

Discussion

Saves the currently unsynced transactions to the server.

Declared In

WHISyncController.h

signupWithEmailAddress: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 ))inCallback

Parameters

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

start

Start automatically synchronizing with the server.

- (void)start

Discussion

Start automatically synchronizing with the server.

Declared In

WHISyncController.h