Getting Started with the iOS Development Kit

If you have not already completed the Getting Started for the iOS API, please do so now. The topics covered in this guide build directly upon those.

While the code samples in the Getting Started guide are appropriate to put in any location that will be executed in your program, we will now put them in a ViewController so that we can see the communication between the iOS device and the firmware, without relying on a console log output.

Please remove the lines from your code that you previously added from the Getting Started Guide.

Setting up Main.storyboard to Display Text

Your project should have been created with a file named Main.storyboard listed on the project explorer pane on the left panel of Xcode. Click on that file to bring up the Xcode Interface Builder window.

You should see a blank canvas with nothing it in. You need to add a UITextView to this canvas. The easiest way to do this is to drag-and-drop a UITextView instance from the Object Library in the Interface Builder. To open the Object Library, click the circular icon with a square inside it in the bottom right pane of the Xcode window:

Scroll down to the element with the name Text View and drag it onto the canvas. Position and resize it as desired so that it's large enough that you'll be able to read it when you run your application.

In the top right area of the Xcode window, select the Assistant Editor tool (two circles overlapping) to bring up a side-by-side of the Interface Builder and a source file:

Ensure that the ViewController.h file is selected in the right window, which should be the default.

Right-click and drag from the UITextView in the Interface Builder and release in the ViewController.h file anywhere after the line @interface ViewController : UIViewController and before the line @end . This will bring up a prompt that asks you to assign a name for the UITextView . For the code below to work, please type the name textView and press "Connect".

You can click the icon to the left of the Assistant Editor icon (see above) to revert to a single window view if you prefer.

Updating the Example Code

Click on the file named ViewController.m listed on the project explorer pane and paste the following code example in place of the method viewDidLoad :

Language:iOS
- (void)viewDidLoad { [super viewDidLoad]; DDPInitializeArgs* args = [[DDPInitializeArgs alloc] init]; args.apiToken = @"@api-token()"; args.simulate = NO; args.useSimulatedCardswipe = YES; args.networkEssid = @"INSERT NETWORK NAME"; args.networkPassword = @"INSERT NETWORK PASSWORD"; self.textView.text = [NSString stringWithFormat:@"Initializing\n%@", self.textView.text]; [DotDashPayAPI.global initialize:args onError:^(DDPError* error) { self.textView.text = [NSString stringWithFormat:@"%@\n%@", error.errorMessage, self.textView.text]; } onInitialized:^(DDPInitialized* response) { self.textView.text = [NSString stringWithFormat:@"Initialized\n%@", self.textView.text]; DDPReceivePaymentDataThenSettleArgs* args = [[DDPReceivePaymentDataThenSettleArgs alloc] init]; args.cents = 128; args.currency = @"USD"; args.useExistingData = NO; args.useExistingDataSecondsWindow = 5; [DotDashPayAPI.payment receivePaymentDataThenSettle:args onError:^(DDPError* error) { self.textView.text = [NSString stringWithFormat:@"%@\n%@", error.errorMessage, self.textView.text]; } onStartedReceivingPaymentData:^(DDPStartedReceivingPaymentData* response) { self.textView.text = [NSString stringWithFormat:@"@Received onStartedReceivingPaymentData response: %@\n%@", response, self.textView.text]; } onReceivedPaymentData:^(DDPReceivedPaymentData* response) { self.textView.text = [NSString stringWithFormat:@"@Received onReceivedPaymentData response: %@\n%@", response, self.textView.text]; } onStartedSettling:^(DDPStartedSettling* response) { self.textView.text = [NSString stringWithFormat:@"@Received onStartedSettling response: %@\n%@", response, self.textView.text]; } onSettled:^(DDPSettled* response) { self.textView.text = [NSString stringWithFormat:@"@Received onSettled response: %@\n%@", response, self.textView.text]; }]; }]; }
copy

Enabling DotDashPay Serial Communication

Next, click on the Info.plist file in the project explorer pane. Right click on the first item in the list (Information Property List) and choose Add Row. In the box that automatically comes up, type Supported external accessory protocols , which should autocomplete.

Click the dropdown arrow at the beginning of this new row, which will reveal the sub-rows. There should already be an existing row named Item 0 . Double click the rightmost area of this sub-row, which will allow you to edit the value of the row. Paste  com.redpark.hobdb9v into the prompt.

Building and Running the Example Code

For these tests, you need to have the app that you're building running on your iOS device. The simplest way to do this is to plug your iOS device into your computer, and run the program on the device. By default, Xcode will run the example code on one of the simulators. To run the code on a device, choose the name of your plugged in device from the target menu at the top of the Xcode window:In the example above, the default run target is a simulated iPad2.

Running the code in this way will install the application on your iOS device, but since it is plugged in to your computer, it cannot communicate with the firmware.

Stop the app via the square button next to the target name in the Xcode menu bar (see above). Disconnect your iOS device from your computer and plug in the DotDashPay Developer Kit Lightning Cable. Re-run the app by clicking the corresponding icon from the iOS device's listed apps.

You should see some output in the text field you created showing you that the iOS device and the firmware are communicating.

Using Braintree as a Sandbox Processor

Sign up for a sandbox braintree account and then on your sandbox account dashboard navigate to Account -> My User at the top of the page. Near the bottom of the page, below API Keys , Tokenization Keys , Encryption Keys , click View Authorizations . Click Generate a New API Key and then click on the newly generated API key. Then copy the Public Key , Private Key , and Merchant ID into the initialize request as follows:

Language:iOS
- (void)viewDidLoad { [super viewDidLoad]; DDPInitializeArgs* args = [[DDPInitializeArgs alloc] init]; args.apiToken = @"@api-token()"; args.simulate = NO; args.useSimulatedCardswipe = YES; args.processorSandboxName = @"braintree"; args.processorSandboxPublicKey = @"Your-Braintree-Public-Key"; args.processorSandboxPrivateKey = @"Your-Braintree-Private-Key"; args.processorSandboxMerchantId = @"Your-Braintree-Merchant-Id"; ... }

Additional Resources

So far, you've implementeed a barebones test. For a bit more control and aesthetic, you can download the DotDashPay Firmware Sandbox example application, which contains all of the above code by default in addition to some extra features.