> For the complete documentation index, see [llms.txt](https://docsjs.ironvest.com/ironvest-authenticaction-developer-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docsjs.ironvest.com/ironvest-authenticaction-developer-documentation/authenticaction-client-sdk/ios-programming.md).

# iOS Programming

## 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 <a href="#toc148556262" id="toc148556262"></a>

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.

<figure><img src="/files/xNFDiWZIx7IMpMbKBcg4" alt=""><figcaption><p>Figure 1. Move unzipped "collector" folder inside your project.</p></figcaption></figure>

* Open your project in Xcode.
* Select Project, Open Project Settings, Switch to Package Dependencies & Click add (as illustrated below)

<figure><img src="/files/LhzNSHszRnM0EygXh2RJ" alt=""><figcaption><p>Figure 2. Add Package Dependencies</p></figcaption></figure>

* Now Click on "Add Local" as illustrated below

<figure><img src="/files/2JE60CZ1E61LazRcML8M" alt=""><figcaption><p>Figure 3. "Add Local" package</p></figcaption></figure>

* Select the package which you added locally

<figure><img src="/files/0Qi5MyW2fDebJ0CjRYbu" alt=""><figcaption><p>Figure 4. Select the "collector" directory &#x26; click on "Add Package"</p></figcaption></figure>

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

<figure><img src="/files/PrpIF1Iy0h1zhVGdG2SB" alt=""><figcaption><p>Figure 5. Choose All packages &#x26; add it to your Target</p></figcaption></figure>

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

<figure><img src="/files/2GG6nY2tPPGnYsQuu1Q4" alt=""><figcaption><p>Figure 6. "collector" as a Package Dependency in Project Navigator View</p></figcaption></figure>

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.

<figure><img src="/files/66wYCXoxtTqGkmkgCdGP" alt=""><figcaption><p>Figure 7. Make Sure dependency is added correctly</p></figcaption></figure>

### Setup Method 2: Using CocoaPods <a href="#toc148556265" id="toc148556265"></a>

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 <a href="#toc148556265" id="toc148556265"></a>

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”.

<figure><img src="/files/tvZBVTICPGnGInj2VQW5" alt=""><figcaption><p><em><strong>Figure 8</strong>: Setting the “Privacy – Camera Usage Description” property in your project.</em></p></figcaption></figure>

{% hint style="info" %}
Please refer to a [short video](https://vimeo.com/919744258/92a51bdeca?share=copy) clip for a demonstration of how the instructions above are applied. &#x20;
{% endhint %}

## iOS Application Programming <a href="#toc148556266" id="toc148556266"></a>

### 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:

```swift
@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.

```swift
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

```swift
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)")
            }
        }
    }
}
```

{% hint style="warning" %}
**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:

{% code overflow="wrap" %}

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

{% endcode %}
{% endhint %}

#### Starting the Camera for Authentic Action

{% hint style="info" %}
NOTE: Make sure to stop the capture, before calling a subsequent startCamera to avoid calling startCamera twice in a row.
{% endhint %}

```swift
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&#x20;

{% hint style="info" %}
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.
{% endhint %}

```swift
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.

```swift
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.

```swift
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.

```swift
// 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()
```

{% hint style="info" %}
Please refer to a short [video clip](https://vimeo.com/919745300/0f924f21b3?share=copy) for a demonstration of how the instructions above are applied. &#x20;
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docsjs.ironvest.com/ironvest-authenticaction-developer-documentation/authenticaction-client-sdk/ios-programming.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
