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.
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.
After that, the new certificate already generated. Click Download Client Certificate to save the Certificate in your local directory.
Add API Endpoint
Set your API Endpoint in admin portal. Go to Settings then Click API Protection.
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.
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.
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.
Generate safouswaap.ini file
Go to Settings, click API Protection then go to API group on left bar. Then select the API group that you want to generate. Click Download Config beside Edit button on the top left.
The popup appeared. Now fill the passphrase with password of your certificate, and name of the certificate that you will be use for the project.
- Client Certificate Passphrase: <passphrase_of_certificate>
- Client Certificate Path: <certificate>.p12
If it is done, click download on the bottom left of popup. Now the safouswaap.ini file are automatically downloaded.
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.
Click Download button in right side of the list for get the SDK into your codebase.
Put Certificate, safouswaap.ini file and Embed the SDK into Example Project.
First you need to create and download the Certificate and safouswaap.ini file configuration from Admin Portal. After that, put the them 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.
After you got safouswaap.ini file configuration from Admin Portal, put it on your project directory. You can simply set from Xcode IDE or put it on your Example project directory.
<SafousWaapExample>/<SafousWaapExample>/safouswaap.ini
Now declare the safouswaap.ini file into the example project code base. The reference is provided in sample code and repository below.
guard let path = Bundle.main.path(forResource: "safouswaap", ofType: "ini") else { return }
ExampleRegistrationViewController L22
Set URL for Example Transaction
Next, set 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-14
let simpleURL: String = "https://simple-web.example-waap.waap.safous.com/"
let echoURL: String = "https://echo.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. |