Implementing Learning Record Store (LRS) with the Tin Can API on iPhone using Objective-C and Rustici Software's Tin Can ObjC library: A Step-by-Step Guide

Implementing Learning Record Store (LRS) with Tin Can API for iPhone

Introduction

In today’s digital learning landscape, it’s essential to have a robust and standardized way of tracking learner progress and achievements. The Tin Can API, also known as xAPI, is an open standard for learning record stores (LRS). It allows learners to share their experiences with others and provides a framework for institutions to track learner progress. In this article, we’ll explore how to implement LRS with the Tin Can API on iPhone using Objective-C.

Understanding the Tin Can API

The Tin Can API is a web service that enables learning platforms to share learner data with other platforms or systems. It uses RESTful architecture and accepts HTTP requests in the following formats:

  • GET: Retrieve learner information
  • POST: Create, update, or delete learner records
  • PUT: Update existing learner records

The Tin Can API also supports statement format, which includes:

  • Statement ID
  • Activity ID
  • Agent ID (the user making the statement)
  • Verbs (verbs used in the activity, e.g., “read”, “completed”)
  • Object (the object being acted upon, e.g., a book title)

Understanding Learning Record Stores (LRS)

A learning record store is a system that stores and manages learner data. LRS accepts statement data via REST interface and provides an API for developers to send statement data.

Step 1: Choose an SDK or Library

To simplify the development process, we can use an SDK or library that abstracts all the calls for us. One such library is Rustici Software’s Tin Can ObjC (now available on GitHub). This library provides a straightforward way to interact with the Tin Can API.

Step 2: Set up your iPhone Project

First, create a new project in Xcode and set up the basic structure:

  • Create a new file named LRSDelegate.h and add the following code:

#import <Foundation/Foundation.h> #import “TCAPI.h”

NS_ASSUME_NONNULL_BEGIN

typedef class TCAPI *TCAPIRef;

@interface LRSDelegate : NSObject

@property (nonatomic, strong) TCAPIRef *tcaapiInstance; @property (nonatomic, copy) NSString *applicationIdentifier;

@end

*   Create a new file named `LRSDelegate.m` and add the following code:
    ```markdown
#import "LRSDelegate.h"

@implementation LRSDelegate

- (instancetype)initWithTCAPI:(TCAPIRef)tcaapiInstance applicationIdentifier:(NSString *)applicationIdentifier {
    self = [super init];
    if (self) {
        _tcaapiInstance = tcaapiInstance;
        _applicationIdentifier = applicationIdentifier;
    }
    return self;
}

- (void)applicationDidFinishLaunching:(NSNotification *)notification {
    // Send a GET request to the LRS server
    [self.tcaapiInstance sendGetRequest:[NSString stringWithFormat:@"%@/statements", self.applicationIdentifier] success:^(TCAPIResponse *response) {
        NSLog(@"Success: %@", response);
    } failure:^(NSError *error) {
        NSLog(@"Error: %@", error);
    }];
}

@end
  • Create a new file named ViewController.h and add the following code:

#import <UIKit/UIKit.h> #import “LRSDelegate.h”

NS_ASSUME_NONNULL_BEGIN

@interface ViewController : UIViewController

@property (nonatomic, strong) LRSDelegate *delegate;

@end


### Step 3: Implement the TCAPI SDK

Now that we have set up our iPhone project and created a delegate class, it's time to implement the Tin Can API using Rustici Software's Tin Can ObjC library.

#### Step 3.1: Import the Library

First, import the library in your Objective-C file:

```markdown
#import <TinCanObjC/TCAPI.h>

Step 3.2: Create a TCAPI Instance

Next, create an instance of TCAPI and initialize it with our application identifier:

TCAPIRef tcaapiInstance = [[TCAPI alloc] initWithApplicationIdentifier:@"your-application-identifier"];

Step 3.3: Add the LRS Delegate

Add your delegate to the TCAPI instance:

tcaapiInstance.delegate = self;

Step 3.4: Send Statements

Finally, send a statement to the LRS server using the sendGetRequest method:

- (void)applicationDidFinishLaunching:(NSNotification *)notification {
    // Create a new statement
    TCAPIStatement *statement = [[TCAPIStatement alloc] initWithAgentId:@"your-agent-id" verb:@"read" object:@"your-object-title"];

    // Send the statement to the LRS server
    [self.tcaapiInstance sendGetRequest:[NSString stringWithFormat:@"%@/statements", self.applicationIdentifier] success:^(TCAPIResponse *response) {
        NSLog(@"Success: %@", response);
    } failure:^(NSError *error) {
        NSLog(@"Error: %@", error);
    }];
}

Conclusion

Implementing a Learning Record Store (LRS) with the Tin Can API on iPhone is a straightforward process that requires an understanding of the Tin Can API and its implementation in Objective-C.

In this article, we covered how to set up your iPhone project, choose an SDK or library, and implement the TCAPI SDK using Rustici Software’s Tin Can ObjC library. We also demonstrated how to send statements to the LRS server using the sendGetRequest method.

By following these steps, you can create a robust and standardized way of tracking learner progress and achievements in your iPhone application.

Step 4: Integrate with Learning Management Systems (LMS)

To take it to the next level, you need to integrate your iPhone app with a Learning Management System (LMS) that supports Tin Can API. This will allow learners to access their learning records and earn badges or certificates.

Here’s an example of how you can use AFNetworking to send a POST request to the LMS API:

- (void)applicationDidFinishLaunching:(NSNotification *)notification {
    // Create a new statement
    TCAPIStatement *statement = [[TCAPIStatement alloc] initWithAgentId:@"your-agent-id" verb:@"read" object:@"your-object-title"];

    // Send the statement to the LMS API
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    NSURL *url = [NSURL URLWithString:@"https://your-lms-api.com/statement"];
    NSDictionary *parameters = @{@"statement": statement};
    [manager POST:url parameters:parameters success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"Success: %@", responseObject);
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        NSLog(@"Error: %@", error);
    }];
}

By integrating your iPhone app with an LMS that supports Tin Can API, you can provide a seamless learning experience for your learners and help them achieve their goals.


Last modified on 2023-10-01