To configure an application to synchronize and retrieve MBO data you must start the client engine, configure the physical device settings, listen for messages from the server, and subscribe to a package.
The client framework uses a callback mechanism to notify the application when messages arrive from the server. Some examples of events that are sent include login success or failure, subscription success or failure, or a change to a MBO.
Register the callback object by executing:
MyCallbackHandler* theCallbackHandler = [MyCallbackHandler new]; [SampleApp_SampleAppDB registerCallbackHandler:theCallbackhandler];
Before performing any action with the Client Object API, make sure the application’s connection information has been entered for this application in Settings.app. To do this, call [SUPMessageClient provisioned]. This method returns YES if the required information is available, and NO otherwise.
If you can connect, create a local database by calling [SampleApp_SampleAppDB createDatabase]. If a local database already exists it will not be overwritten. Next, call startBackgroundSynchronization. You must perform these calls before you call [SUPMessageClient start] to connect to the Unwired Server.
if ([SUPMessageClient provisioned]) { [SampleApp_SampleAppDB createDatabase]; [SampleApp_SampleAppDB startBackgroundSynchronization];
[SUPMessageClient start]; }
[SampleApp_SampleAppDB beginOnlineLogin:@"supUser" password:@"s3pUser"];
[SampleApp_SampleAppDB subscribe];
If the subscription request was accepted the callback handler will receive a notification. If successful, the Unwired Server sends out a push message to the client application containing the application data. The Unwired Server also sends an acceptance message. The client receives the push and acceptance messages.
The client framework notifies the application of the result of success through an onSubscribeSuccess callback, if a callback function is registered. If an error occurs in the subscription process, the Unwired Server sends out a rejection message for the subscription. The client receives a subscription request result notification message with failure from the Unwired Server, and may resubmit the subscription request.
The client framework notifies the application of the result of failure through the onSubscribeFailure callback, if a callback function is registered.
On subsequent launches of the application the client must ask the server to send any updates that happened since the last time the application was run.
Since a subscribe request is only sent out once, no matter how many times the subscribe method is called on the database, you can take advantage of this in the onLoginSuccess callback.
-(void)onLoginSuccess:(NSNotification *)obj { if (![SampleApp_SampleAppDB isSubscribed]) { [SampleApp_SampleAppDB subscribe]; } else { [SampleApp_SampleAppDB beginSynchronize]; } }