IronVest AuthenticAction Developer Documentation
  • AuthenticAction Client SDK
    • Components and Considerations
    • 📱Android Programming
    • 📱iOS Programming
    • 🖥️JavaScript Programming
  • Service Components
    • The AuthenticAction Service
    • The AuthenticAction Data
    • REST Endpoint Reference
Powered by GitBook
On this page
  • iOS Xcode Project Setup
  • Setup Method 1: Adding dependencies using SPM
  • Setup Method 2: Using CocoaPods
  • Setting Permissions in Info.plist
  • iOS Application Programming
  • AASDKManager
  • Initialising SDK
  • Capturing Data from Custom Input Fields
  • Troubleshooting
  1. AuthenticAction Client SDK

iOS Programming

PreviousAndroid ProgrammingNextJavaScript Programming

Last updated 7 months ago

iOS Xcode Project Setup

These instructions assume a development methodology leveraging Swift programming language; you will be adding the AuthenticAction™ SDK to your iOS project within Xcode. A programmatic interface to the IronVest SDK is provided using standard iOS framework architecture.

Xcode and the Xcode logo are trademark and property of Apple Inc.

Setup Method 1: Adding dependencies using SPM

IronVest will supply the necessary libraries in the form of a zip file containing the Swift Package. Complete the following steps to import the framework into your Xcode project:

  • Download the .zip which contains Collector Framework

  • Unzip the contents of the zip file

  • Move "Collector" folder inside your project. Place it as illustrated below.

  • Open your project in Xcode.

  • Select Project, Open Project Settings, Switch to Package Dependencies & Click add (as illustrated below)

  • Now Click on "Add Local" as illustrated below

  • Select the package which you added locally

  • Now, Select all packages & select Target in which you wish to add those packages

  • After import, this is how your project structure would look like & at the bottom, it would show up dependency which we just added.

Linking and Embedding the SDK Framework

Ensure that the dependency is available to your application, Open Project settings, select target, switch to General Tab & make sure that dependency is added as illustrated below.

Setup Method 2: Using CocoaPods

Open your project's Podfile and add following line

Make sure that you specify full path of the SDK.

target 'MyApp' do
  pod 'collector', :path => '/Users/sagar/ironvest/collector'
end

Setting Permissions in Info.plist

For specific functionalities that the collector framework leverages, the user will be prompted to allow the permissions. To inform your user and increase the likelihood that they will allow the permission when prompted, you will need to ensure the appropriate permissions explanations are set in your bundles Info.plist file.

Specifically, the collector framework leverages the camera and screen capturing functionalities. To set these permissions descriptions within your Xcode project, follow these steps:

  1. Open the “Info” View in your project settings.

  2. Expand “Custom iOS Application Target Properties” section.

  3. Look for the key “Privacy-Camera Usage Description”; if it is not available, select one of the “+” buttons and scroll down the list to find it and add it to the list.

  4. Change the value to a suitable description for your user, explaining why you want the permission; For example, “$(PRODUCT_NAME) would like camera permission so that AuthenticAction security can protect your session”. (see figure 8).

  5. Add the Key “Privacy – Photo Library Usage Description”, similarly setting the value to something that will make sense to your user (see figure 7), such as “$(PRODUCT_NAME) would like photo library permission so that AuthenticAction security can protect your session”.

iOS Application Programming

AASDKManager

AASDKManager is an interface with which you can easily access most of the SDK features.

With AASDKManager, as a programmer, you can focus on utilising features with provided singleton-interface.

Initialising SDK

The general collector allows for using the camera along with some sensor collecting.

You can start listening and collecting sensor events like this:

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {
        setupAASDK()
        return true
    }

    func setupAASDK() {
        let cid = "customer_id_goes_here" // this will be provided by IronVest
        let baseUrl = "base_url_goes_here" // this will be provided by IronVest
        AASDKManager.shared.setupSDK(
            nil, // supply csid (customer session identifier) if you already have it.
            userId: nil, // supply userId if you already have it.
            cid: cid,
            baseUrl: baseUrl
        ) {
            debugPrint("AA SDK is initialised")
        }
    }
}
  • cid = Customer Specific Identifier. This identifier will be provided by IronVest

  • baseUrl = This baseUrl will be provided by IronVest

  • csid = Customer Session Identifier. Usually it's a unique session identifier for each user session. This is the identifier by which the session can be queried during validation or looked for in the dashboard

  • userID = Unique User Identifier.

Update CSID & UserID

If CSID or UserID change later or either of the values was not available during the initial initialization, they can be updated later.

import collector

class AuthViewController: UIViewController {
    @IBAction func loginClicked() {
        AASDKManager.shared.updateCSID(csid)
        AASDKManager.shared.updateUserId(obsId)
    }
}

Using camera preview inside a UIKit project

Make sure to add NSCameraUsageDescription to Info.plist

Setup Camera & Preview

import collector

class ChangePasswordViewController: UIViewController {

    @IBOutlet var cameraPreviewContainerView: UIView!

    override func viewDidLoad() {
        super.viewDidLoad()
        cameraSetup()
    }

    func cameraSetup() {
        // first parameter view-controller
        // second parameter view
        // second parameter view is optional. 
        // If you don't want camera preview, you can send view as nil
        AASDKManager.shared.setupViewController(self, view: cameraPreviewContainerView) { error in
            if let error = error {
                debugPrint("Error setting up the camera - \(error.localizedDescription)")
            }
        }
    }
}

IMPORTANT NOTE: Some device versions may not perform correctly when a camera preview is shown on a screen that has also a password input field presented. To avoid this it's recommended to use the option to run the SDK with active auth collector without camera-preview. The following lines demonstrate how this can be achieved:

AASDKManager.shared.setupViewController(self, view: nil) {
    if let error = error {
        debugPrint("Error setting up the camera - \(error.localizedDescription)")
    }
}

Starting the Camera for Authentic Action

NOTE: Make sure to stop the capture, before calling a subsequent startCamera to avoid calling startCamera twice in a row.

import collector
import cameraCollector

class ChangePasswordViewController: UIViewController {

    @IBOutlet var cameraPreviewContainerView: UIView!

    @IBAction func startCamera() {
        // instead of nil, you can also send action name
        // e.g. "change_password", "change_email", "checkout", "payment" etc.
        AASDKManager.shared.startCapture(nil) { error in
            if let error = error {
                debugPrint("Error setting/starting up the camera - \(error.localizedDescription)")
            }
        }
    }

Stopping the camera for Authentic Action

NOTE: Make sure to stop the capture, once the authentic action is completed. Without it, front-camera will stay open & your application will keep collecting camera frames and continuously show the green camera indicator to a user.

import collector
import cameraCollector

class ChangePasswordViewController: UIViewController {

    @IBOutlet var cameraPreviewContainerView: UIView!

    @IBAction func stopCamera() {
        AASDKManager.shared.stopCapture()
    }

Capturing Data from Custom Input Fields

In some of the cases, App may need to submit data from custom fields.

E.g. item picker, date picker, segment-control, switch on-off, check-boxes.

For such scenarios, you can use external Event provider.

Collector.shared.externalEventProvider.provideInputEvent(
    eventType: .Change,
    elementId: "accessibilityId", // e.g. birthday-date-picker-id
    elementName: "elementName", // e.g. birthday-date-picker
    inputType: .Text,
    sourceClassName: contentView,
    inputText: value
)

Here are the input types for such external events.

case Text = 1
case Password = 2
case Checkbox = 3
case Radio = 4
case Submit = 5
case Reset = 6
case File = 7
case Number = 8
case Date = 9
case SelectOne = 10 // single selection dropdown
case SelectMultiple = 11 // multiple selection dropdown
case Other = 12
case Error = 13

Troubleshooting

The SDK generates logs throughout its execution. The most recent logs are stored in memory and can be retrieved for problems troubleshooting. Below is an example of how these logs can be put in a variable or in the Pasteboard to be shared with someone else.

// Example 1: Collecting Logs in a variable
var sdkLogs = Collector.shared.getLogs()

// Example 2: Collecting logs into Pasteboard & App-User can paste it anywhere (whatsapp, mail, telegram etc)
UIPasteboard.general.string = Collector.shared.getLogs()

Please refer to a clip for a demonstration of how the instructions above are applied.

Please refer to a short for a demonstration of how the instructions above are applied.

📱
short video
video clip
Figure 1. Move unzipped "collector" folder inside your project.
Figure 2. Add Package Dependencies
Figure 3. "Add Local" package
Figure 4. Select the "collector" directory & click on "Add Package"
Figure 5. Choose All packages & add it to your Target
Figure 6. "collector" as a Package Dependency in Project Navigator View
Figure 7. Make Sure dependency is added correctly
Figure 8: Setting the “Privacy – Camera Usage Description” property in your project.