Making Changes to Application Initialization

Make changes to the application to allow it to initialize as required in 2.1 ESD #3.

  1. Locate the following initial synchronization code from the Tutorial: iOS Object API Application Development in 2.1 ESD #2.
    [SUP101SUP101DB beginOnlineLogin:supuser password:suppass];

    In an MBS application, subscribe caused data to be pushed to the client from the server. In your RBS application, you must invoke synchronize (synchronous replay) or beginSynchronize (asynchronous replay).

    An RBS application can synchronize through either a synchronous or asynchronous process. By default, asynchronous replay is enabled. When asynchronous replay is enabled, the server returns after processing the operation replay records that are uploaded to the server in the synchronization session When asynchronous replay is disabled, the server returns after processing the operation replay records that are uploaded to the server, then downloads the results of those operation replay records to the device.

  2. Set the login credentials for the database synchronization.
    SUPConnectionProfile *sp = [SUPSampleSUPSampleDB getSynchronizationProfile];  
    [sp setUser:@"supAdmin"];
    [sp setPassword:@"supPwd"]; 
  3. The generated code already sets the required connection properties for database synchronization. If you are using manual registration and change the default connection properties (for example, if you are connecting through a Relay Server), then reset them as follows:
    [sp setServerName:@"relayservername.com"];
    [sp setNetworkProtocol:@"networkProtocol"];
    [sp setPortNumber:portNumber];
    [sp setNetworkStreamParams:@"trusted_certificates=certificateName.com;compression=zlib;url_suffix=farmIDForRBS"];
  4. Replace the code with code for either asynchronous or synchronous synchronization.

    For synchronous synchronization:

    [sp setAsyncReplay:NO];
        	
    @try {
      [SUP101SUP101DB synchronize];
    }
    @catch (NSException *exception) {
      MBOLogError(@"%@: %@", [exception name], [exception reason]);
    } 

    If the AsyncReplay flag is turned off, the client object API calls the onSynchronize callback method with an SUPSynchronizationStatus_ FINISHING status after the synchronize.

    Note: In MBS, the generated operation is automatically sent to the Unwired Server. In your RBS applications, you must instead invoke the synchronize method to send the record to the Unwired Server. The synchronize method is a blocking call.

    For asynchronous synchronization:

    [sp setAsyncReplay:YES];
    @try {
    [SUP101SUP101DB synchronize];
    // or using beginSynchronize to create a background synchronization request.
    //   SUP101SUP101DB beginSynchronize];
    		
    }
    @catch (NSException *exception) {
      MBOLogError(@"%@: %@", [exception name], [exception reason]);
    } 

    If the AsyncReplay flag is turned on, the client object API calls the onSynchronize callback method with an SUPSynchronizationStatus_ASYNC_REPLAY_UPLOADED status after the synchronize, followed by an SUPSynchronizationStatus_FINISHING status.

    Note: Control returns immediately, without the replay results synchronized to the client. The beginSynchronize method is a nonblocking call. You can use this method from the SUPDefaultCallbackHandler to get callbacks once the replay completion notification is received.
    -  (SUPSynchronizationActionType)onSynchronize:(SUPObjectList*)syncGroupList withContext:(SUPSynchronizationContext *)context

    The above code examples synchronize the default group. Alternatively, you can synchronize based on the synchronization group the MBO belongs to. Replace the code [MBO getSynchronizationGroup] in your application with:

    NSString *mbo_sg = [mbo metaData].synchronizationGroup;
    [db synchronize:mbo_sg]; 

    The following methods in the registered callback handlers of the database class are called when the replay results are received and processed by the client framework.

    • - (void)onReplayFailure:(id)entityObject
    • - (void)onReplaySuccess:(id)entityObject

    When you disable AsyncReplay in the synchronization profile, the database class synchronize is a blocked call. When the method returns, the server data has been synchronized in the database. You no longer need to include a wait period in the code.

    Remove this code from your application:

    while ([SUP101SUP101DB hasPendingOperations])
    {
      [NSThread sleepForTimeInterval:1];
    }