Example of Using iOS SDK

This article explains how to use example code properly for iOS SDK

Configuration in Admin Portal


Before implementing the example code, you need to configure several things such as generate Trusted Certificate, Add API Endpoints,  and Create API Group.

1

Then click Generate Certificate. Fill the certificate name as you want, and do not forget to fill the PassPhrase Certificate. If you finish, click Generate on right below.

2

After that, the new certificate already generated. Click Download Client Certificate to save the Certificate in your local directory.

3

Add API Endpoint

Set your API Endpoint in admin portal. Go to Settings then Click API Protection. 

example-1

To create new API Endpoint, click New API Endpoint in right above. create simple web API Endpoint for testing. You need to add New API Endpoint and fill the form like this:

  • Name: simple-web
  • Endpoint Address/FQDN/Hostname: 192.168.0.1
  • Protocol: HTTP (or HTTPS. It's depends on your environment)
  • Other settings: using default settings (no changed)

Click Save if you finished.

6

Create New Default API Group

As a summary for those API Endpoint that already created, you need create an API group. Go to Settings, click API Protection then go to API group on left bar.

7

Click New API Group on right above. Fill the form with the instruction below:

  • API Group Code: default
  • Description: Default Group Description (or fill as you want)
  • Trusted Certificate: cert-1
  • API Application (Main): simple-web

After that, click Save.

example-2

Download Source Code of the Example Code

Get the example code from GitHub by clone the repository.

https://github.com/iij-safous/safous-waap-sdk-ios-example

After clone the example code repository, open the project in Xcode IDE.

Get the SDK from Admin Portal.

Get the WAAP SDK for iOS from admin portal. Login to admin portal, then go to Settings then click SDK on left bar. You will see the list of SDK version that WAAP release.

9-ios

Click Download button in right side of the list for get the SDK into your codebase.

Put Certificate and Embed the SDK into Example Project.

First you need to create and download the Certificate from Admin Portal. After that, put the Certificate into the Example project.

For SDK, you can put into the Example Project by adding it as Embedded Frameworks Content in General Section on Project. More detail steps provided in this Configuration Page.

Setup Environment and update URL

As a reminder, consider to take a look at the Admin Portal for setup the API endpoints. There are 2 parts that needs to be create. First you have to create 3 Endpoints for setup the registration environments. There are Authentication, Registration, and Verification. It may look like the image below.

10

Second, you need to create an API Endpoints for testing. There is a Simple API Endpoint. If it is done, It may look like the image below.

11-ios

Now back to Xcode IDE while you recently opening the Example Project. Open the SafousWaap.plist file as configuration. As example you can take a look on the line from repository below. make sure the 3 important Endpoints for Registration are set exactly same like you create on Admin Portal.

SafousWaap.plist File

<dict>
    <key>X-AppId</key>
    <string>default</string>
    <key>CertificateName</key>
  <string>CERTIFICATE_NAME</string>
    <key>CertificatePassword</key>
  <string>PASSPHRASE_PASSWORD_CERTIFICATE</string>
    <key>BaseUrl</key>
    <dict>
        <key>Device</key>
        <string>https://waap-register.example-waap.waap.safous.com/</string>
        <key>Auth</key>
        <string>https://waap-auth.example-waap.waap.safous.com/</string>
        <key>VerifyToken</key>
        <string>https://waap-client-verification.example-waap.waap.safous.com/api/device/verify</string>
    </dict>
</dict>

Next, update the URL for Transaction module. Open TransactionExampleViewController swift file in Example Project. Set the URL that you already created in Admin Portal. There is a line of code below from repository to help you set the Simple API url.

ExampleTransactionViewController L13

let simpleURL: String = "https://simple-web.example-waap.waap.safous.com/"

Build and Run the Example Code Project

Now you ready for Build and Run the Example Project. Go to Product on Main tab the click Build (Command+B). The project will processing and refactor itself. After it finished, back to Product tab on Main then click Run (Command+R). The RegistrationExampleViewController and TransactionExampleViewController will generate the result and had a different purposes with the detail below.

Class Description
RegistrationExampleViewController This is an example of registration, using registerDevice and verifyDevice method
TransactionExampleViewController This is an example of transaction, using transaction method of simple-web API endpoint and Terminate method.