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.

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

Provide a Product Name and Company Identifier and complete the New Project 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.

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

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).

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

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

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

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.

For the DOL Service Operation 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.

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.

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).

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

Synthesize the two ivars we created earlier.

- 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 :

For DOL service operation :

- 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 :

For DOL service operation :

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

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 :

For DOL service operation :


View DOL Data
Build and run the application, and you should see something like the following:
For DOL API datasets :

For DOL API datasets :
