Developer Tutorial - iOS

Getting Started

Add RSOfflinePlayer-combined.a, the RSOfflinePlayer header files and the RSOfflinePlayerResources.bundle file to your Xcode project and make sure they are linked and exported properly in your project target.

Authentication

Authentication for the SDK is handled by the host application and not the Rustici Engine. This is the most flexible solution for adding the SDK to existing applications as well as new projects. The host application will handle the user login and will provide any necessary authorization details to the SDK when required.

Playing Content

To play the offline package, a RSOfflinePlayer object needs to be created by supplying a valid Rustici Engine ExternalPackageId, ExternalRegistrationId and ExternalConfiguration to the service along with the remote Rustici Engine URL and paths.

rsop = [[RSOfflinePlayer alloc] initWithPackageId:_packageId withRegistrationId:_registrationId withConfiguration:_configuration withUserId:@"" withRemoteServer:[RSUtil getValueFromConfig:@"remote-server"] withRemotePaths:remotePaths withRemoteCredentials:remoteCredentials  withCompletionBlock:^{

   [rsop setRemoteServerUrl:[NSURL URLWithString:[RSUtil getValueFromConfig:@"remote-server"]]];
   //Create a URL object.
   NSURL *url = [NSURL fileURLWithPath:rsop.packageLaunchUrl];
   //URL Requst Object
   NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];

   _wv.delegate = self;

   [[NSURLCache sharedURLCache] removeAllCachedResponses];
   _wv.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
   //Load the request in the UIWebView.
  [_wv loadRequest:requestObj];
} withErrorBlock:^(NSError *error){
   UIAlertView *errorAlert = [[UIAlertView alloc] initWithTitle:@"Error!"
              message:[NSString stringWithFormat:@"There was an error loading that package. \n %@", [error userInfo]]
              delegate:nil
    cancelButtonTitle:@"OK"
    otherButtonTitles:nil];
   [errorAlert show];
   } isOnline:[_isOnline boolValue]];

Syncing Results

The SDK relies on the host application to create a UIWebView and navigate to the rsop.packageLaunchUrl as the start page. When the host application wants to sync the course data, it grabs the current values from the UIWebView’s content and sends it to the SDK for syncing. The host application supplies the isOnline value to allow various definitions of ‘online’ to be determined by the host application.

- (IBAction)updateData {
    //get the current runtimeXML from the player

    NSString *runtimeXml = [_wv stringByEvaluatingJavaScriptFromString:@"Control.GetXmlForDirtyData();"];
    //get the current Javascript object from the player
    NSString *attemptInfo = [_wv stringByEvaluatingJavaScriptFromString:@"GetCurrentRegistration();"];
    //send both bits of data to the SDK
    [rsop syncCurrentSessionWithAttemptInfo:(NSString*)attemptInfo WithRuntimeXml:runtimeXml withOptions:nil withCompletionBlock:^{
      } withErrorBlock:^(NSError *error){} isOnline:[_isOnline boolValue]];  
    }

Getting Current Device Status

To get the current SCORM status for a registration, you can use the RSOfflinePlayer’s getCurrentStatus service. If you are offline, the most recent results from the local datastore are returned. If you are online, the data will be pulled from the Rustici Engine server and then checked against the latest local results to ensure the most recent or completed attempt is used.

[RSOfflinePlayer getCurrentStatusForUser:_userName withRegistrationId:[catObj valueForKey:@"registrationId"] withConfiguration:[catObj valueForKey:@"configuration"]] forKey:@"attemptDetail"];

Deleting Local Content

The host application can use the SDK to delete content from the device when the user is finished with it and synced the results back to the Rustici Engine. Using RSOfflinePlayer’s deletePackage service will delete the package folder from the local filesystem as well as all of the session information in the datastore.

Special measures should be taken by the host application to not allow this for multi-user setups where once user could delete the package while another is still using it.

[_catalog deletePackageById:_packageId withCompletionBlock:^{
       NSLog(@"package deleted");
   } withErrorBlock:^(NSString *errorCode){
       NSLog(@"package delete error %@", errorCode);
   }];

results matching ""

    No results matching ""