Example of Using IOS SDK

You need to do some step before your application is running with SDK, such as :

Creating an interface class


Creating class ViewController: UIViewController

Create an ViewController.Swift 

import UIKit
import SafousWaap

class ViewController: UIViewController {
  override func viewDidLoad() {
      super.viewDidLoad()
        // Do any additional setup after loading the view.

      // MARK: transaction
      SafousWaap.shared.transaction (
          onSuccess: {
            response in
            print(response)
            },

          onError: {
            error in
              print(error)
          }
    )
}
}

Create Response Model


Creating ViewController2.m 

#import < Foundation / Foundation.h >
  #import "ViewController2.h"

@import SafousWaap;

@interface ViewController2()

@end

@implementation ViewController2

-
(void) viewDidLoad {
  [super viewDidLoad];
  // Do any additional setup after loading the view.
    // MARK: Transaction

  SafousWaap * safousWaap = [
    [SafousWaap alloc] init
    ];

  [safousWaap transactionOnSuccess: ^ (NSString * result) {
      NSLog(@ "%@", result);
    }
    onError: ^ (NSString * error) {
      NSLog(@ "%@", error);
    }
    ];

Working with Simple Code


add the below code to it. Comments are added in the code to get to know in detail.

//  SafousWaapExample
//  AppDelegate.swift
import UIKit

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow ?

      func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any] ? ) -> Bool {
      // Override point for customization after application launch.
        self.window = UIWindow(frame: UIScreen.main.bounds)

        let storyboard = UIStoryboard(name: "Main", bundle: nil)

      if let vc = storyboard.instantiateViewController(withIdentifier: "ViewController2") as ? ViewController2 {
        window?.rootViewController = vc
        }

        window?.makeKeyAndVisible()

      return true
    }
  }

//  SafousWaapExample/SafousWaap.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
      <key>X-AppId</key>
      <string>c3395dcc-c41a-4076-bee9-87a331048f32</string>
      <key>CertificateName</key>
      <string>device.xxxx.xxxx.safous.com/</string>
      <key>CertificatePassword</key>
      <string>Safous123</string>
      <key>BaseUrl</key>
      <dict>
          <key>Device</key>
          <string>https://device.xxxx.xxxx.safous.com</string>
          <key>Auth</key>
          <string>https://auth.xxxx.xxxx.safous.com</string>
        <key>VerifyToken</key>
          <string>https://device.xxxx.xxxx.safous.com/</string>
      </dict>
  </dict>
</plist>

//for example ViewController.swift
//  SafourAuthExample

import UIKit
import SafousWaap
//Setup envi & mobile init xcframwork

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        SafousWaap.shared.transaction(
          //mobile hit api Back End with function sdk
          onSuccess: {
            // onSuccess: Success response with payload
            response in

            guard
            var urlRequest = response,
              let url = URL(string: "www.example.com")
            // url: Full url
            else {
              return
            }
            urlRequest.url = url
            urlRequest.setValue("Real Date XXXX", forHTTPHeaderField: "Date")
            // headers: Headers (optional)
            urlRequest.setValue("Authorization XXXXX", forHTTPHeaderField: "Authorization")
            // headers: Headers (optional)
            urlRequest.httpMethod = "GET"
            // method: .get or .post

            URLSession.shared.dataTask(with: urlRequest, completionHandler: {
              // this is for handling response
            (data, response, error) in
          })
          },
          onError: {
            error in
            print(error)
          }
        )
}
}