Configuring an Application to Synchronize and Retrieve MBO Data

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.

  1. Register a callback.

    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];
    Note: See Developer Guide for iOS > Reference > iPhone Client Object API > Utility APIs > Callback Handlers for more information on the Callback Handler interface. See Developer Guide for iOS > Development Task Flows > Developing Applications in the Xcode IDE > Referencing the iPhone Client Object APIfor more information on a sample application which includes a callback function.
  2. Make sure the client settings have been entered, and then create the database and call startBackgroundSynchronization.

    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];
    
  3. Start the Sybase Unwired Platform client engine by connecting to the Unwired Server.
    [SUPMessageClient start];
    }
    If the messaging client is able to connect to the Unwired Server, the callback handler will receive a notification.
  4. After receiving notification that the application has successfully connected to the server to which the application has been deployed, when the application sends a request, the Client Object API puts the current user name and credentials inside the message for the Unwired Server to authenticate and authorize. The device application must set the user name and credential before sending any requests to the Unwired Server. This is done by calling the beginOnlineLogin API.
    [SampleApp_SampleAppDB beginOnlineLogin:@"supUser" password:@"s3pUser"];
    If login to the Unwired Server was successful the callback handler will receive a notification. Any security failure results in a rejection of the request and notification through the callback handler.
  5. After receiving notification that login was successful, subscribe to the database.
    [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.

  6. The first time the application launches and successfully connects to the server, an initial import is done to populate the local database. When an entity is sent to the client the client framework notifies the application through the onImport: notification. When all of the initial objects have been sent, the client framework notifies the application through the onImportSuccess notification.

    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];
        }
    }