Skip to page content
Secretary of Labor Hilda L. Solis

iOS DOL Data SDK Sample

Overview

This sample will provide the steps to create a simple iOS app that can consume DOL Data. Following these steps in order will allow your app to operate correctly. Download this project | Download project for Service Operation.

Create a New Project

From the file menu in Xcode select New -> New Project.

Create New Project in Xcode

Choose a template for your project. For this example we choose Navigation-Based Application.

Select Template for Navigation based application

Provide a Product Name and Company Identifier and complete the New Project wizard.

Provide Product Name and Complete Wizard

Add Dependencies

The DOL Data SDK has some library dependencies we must add to the project. From the left pane choose the project (top level in the list), then from the center pane select the target. From the right pane choose the Build Phases tab.

Go to Build Phases and library dependencies

Expand the Link Binary with Libraries section. Click the + button to add the required frameworks. From the list that pops up choose:

  • libz.1.2.3.dylib
  • MobileCoreServices.framework
  • CFNetwork.framework
  • SystemConfiguration.framework
Tip: you can hold down the Command key to select multiple files.

Required Libraries are libz.1.2.3.dylib,MobileCoreServices.framework,CFNetwork.framework,SystemConfiguration.framework

Add SDK to Project

Add the SDK to your project. Extract the zip file (which can be downloaded here) and drag-and-drop the DOLDataSDK folder to you project root (the first item on the left pane).

Add SDK to your project

From the option screen that pops up choose 'Copy items into destinations group folder' and 'Create groups for any added folders'.

Copy Items

Test that all the steps above have been done correctly by building the application. From the product menu, select Product -> Build.

Build Project

The status area at the top center should display that the build succeeded with no issues.

Build Successful

Locate Dataset Path

Each Dataset has a Dataset Location path that gives the URL that will be needed for the data request. This address is circled in red.

Locate Dataset Path for DOl API Dataset Sample please use http://api.dol.gov/V1/Compliance/WHD

For the DOL Service Operation sample please use http://api.dol.gov/V1/SummerJobs

Locate Dataset Location path from Dataset, for Summer Job Plus Sample please use http://api.dol.gov/V1/SummerJobs

The data request will also need the location of the table you are pulling data from. The tables are listed under their datasets. This table's name is circled in red.

Table Name

Create the Root View Controller

Open RootViewController.h.

  • We must modify the class so that it can respond to the DOLDataRequest delegate methods. Do this by adding the <DOLDataRequestDelegate> protocol to the class.
  • Add a NSArray ivar to store the results (*arrayOfResults).
  • Add a DOLDataRequest ivar. This is how we will make requests to the API.
  • Create properties for both ivars.
 Modifed RootViewController.h class to response to the DOLDataRequest delegate methods

Open RootViewController.m. Add #define constants for your API Key, Secret and Host. In a real production application, you may choose to store this information elsewhere (keychain, plist, etc).

#define Constants

For DOL Service Operation (e.g. Summer Job Plus) please import additional header file json parsing which is JSON.h

#define Constants and import json class to json result for DOL data service

Synthesize the two ivars we created earlier.

Synthesis

In this example we make the API call as soon as the app launches.
  • Create a DOLDataContext object. This object stores the API key information and URL.
  • Alloc init the DOLDataRequest ivar with the context object as parameter.
  • Set self as the delegate. This ensures that this class' DOLDataRequestDelegate methods are called when the API call completes.
  • Create an NSDictionary and store the arguments you want to send with the API call
  • Call callAPIMethod:withArguments:, providing the Dataset Location path, table name, and arguments dictionary. This will execute asyncronously.

For DOL API datasets :

viewDidLoad sample code for DOL Data API

For DOL service operation :

viewDidLoad sample code for DOL service operation

Implement the DOLDataRequestDelegate method didCompleteWithResults:.
  • Store results to the NSArray ivar. We need to retain the array because it is autoreleased. Otherwise the app will crash when the table refreshes.
  • Reload the table view.

For DOL API datasets :

dolDataRequest:didCompleteWithResults: assign result array to local array variable to reload the table view from local array variable

For DOL service operation :

dolDataRequest:didCompleteWithResults:assign result array to local array variable to reload the table view from local array variable

Implement the DOLDataRequestDelegate method didCompleteWithError:. In this example we chose to just show the error in an UIAlertView.

dolDataRequest:didCompleteWithError:

Complete the table view requirements:

  • Return the count for the results array in the numberOfRowsInSection: method
  • In the cellForRowAtIndexPath: method create an NSDictionary variable pointing to the object in the results NSArray whose index is equal to the row we are rendering.
  • Now we can set the cells text labels to any property of the NSDictionary.
  • The NSDictionary keys will be equal to the table column names.

For DOL API datasets :

Table View Methods

For DOL service operation :

Table View Methods for DOL service operation

Release any objects in the dealloc method.

Dealloc

View DOL Data

Build and run the application, and you should see something like the following:

For DOL API datasets :

Completed App

For DOL API datasets :

Completed App : DOL Service operation result