# iOS Framework

The **Mobile EMV** SDK enables iOS apps to accept EMV chip card payments via Bluetooth or audio jack using the [IDTech VP3300](https://app.gitbook.com/s/ek5aF2vccbKrklw8djdB/devices/id-tech#id-tech-vp3300-reader) card reader.

### **Prerequisites** <a href="#prerequisites" id="prerequisites"></a>

To enable the Mobile EMV SDK into your iOS app, ensure you have following:

✅ API access key issued to you by Xplor Pay.

{% hint style="info" %}
Visit [Let's Get Started - Xplor Pay](https://xplorpay.com/getting-started/) to get API access key.
{% endhint %}

{% stepper %}
{% step %}

### Set up mobile card reader

To set up the mobile card reader:

1. Turn on the reader.

{% hint style="warning" %}
The reader must be fully charged before you turn it on.
{% endhint %}

2. Enable **Bluetooth** on your iOS device.

{% hint style="success" %}
The reader automatically pairs with your iOS device when Bluetooth is on.
{% endhint %}

3. Insert the chip side of the card into the reader’s slot and wait until the green LED flashes.

{% hint style="success" %}
This confirms a successful card read.
{% endhint %}
{% endstep %}

{% step %}

### Connect iOS app

To connect your iOS app to the card reader:

1. Install SDK dependencies, such as `IDTech.xcframework` , `IDTech.bundle` (v4.0.142 or later) and `CocoaLumberjack.xcframework` .
2. Add the iOS Framework to your project using Carthage.

{% code overflow="wrap" lineNumbers="true" %}

```javascript
github "Clearent/iOS-framework"
carthage update
```

{% endcode %}

3. Import the iOS framework header in your code.

{% code overflow="wrap" lineNumbers="true" %}

```javascript
#import <ClearentIdtechIOSFramework/ClearentIdtechIOSFramework.h>
```

{% endcode %}

4. Initialize the SDK and connect to the card reader.

{% code lineNumbers="true" %}

```javascript
ClearentConnection *connection = [[ClearentConnection alloc] initBluetoothSearch];
                                  [clearentVP3300 startConnection:connection];
```

{% endcode %}

The iOS Framework connects automatically to the card reader using Apple’s Bluetooth implementation through the IDTech library.

{% hint style="success" %}
The reader’s middle LED flashes *green* when successfully paired.
{% endhint %}
{% endstep %}

{% step %}

### Process payment

To process the payment in your iOS app:

1. Configure the SDK to initiate an EMV card transaction that sends the encrypted token to Xplor Pay.

{% code lineNumbers="true" %}

```javascript
ClearentVP3300Config *config = [[ClearentVP3300Config alloc] init];
[config setPublicKey:publicKey];
[config setClearentBaseUrl:baseURL];
config.contactAutoConfiguration = false;
config.contactlessAutoConfiguration = false;
config.contactless = true;
clearentVP3300 = [[Clearent_VP3300 alloc] initWithConnectionHandling:self
                                    clearentVP3300Configuration:config];
clearentManualEntry = [[ClearentManualEntry alloc] init];
[clearentManualEntry setClearentBaseUrl:baseURL];
[clearentManualEntry setPublicKey:publicKey];
```

{% endcode %}

2. Set up a payment request.

{% code lineNumbers="true" %}

```javascript
ClearentPayment *payment = [[ClearentPayment alloc] init];
[payment setAmount:theAmount];
payment.amtOther = 0;
payment.type = 0; // Sale
payment.timeout = 10;
payment.tags = nil;
payment.fallback = true;
payment.forceOnline = false;
```

{% endcode %}

3. Initiate a card transaction.

{% code lineNumbers="true" %}

```javascript
ClearentResponse *response = [clearentVP3300 startTransaction:payment
                                         clearentConnection:connection];
if (response.responseType != RESPONSE_SUCCESS) {
    // Notify user transaction could not be started
}
```

{% endcode %}

The Mobile EMV SDK reads the card and encrypts the card data.

4. Add the callback handlers to receive the successful message from the Mobile EMV SDK.

{% code lineNumbers="true" %}

```javascript
- (void)successTransactionToken:(ClearentTransactionToken *)token {
    // Send the encrypted JWT to the Mobile Payments API
    // POST /rest/v2/mobile/transactions/sale
}
```

{% endcode %}

The Mobile EMV SDK returns an encrypted JSON Web Token (JWT) that contains the transaction data.

5. Use the POST method to send the transaction request to the [Mobile Payment Transactions](https://app.gitbook.com/s/j9heLdoDRsfnChUQohvj/api/payments/mobile/mobile-payment-transactions "mention") endpoint to process the payment.
   {% endstep %}
   {% endstepper %}


---

# Agent Instructions: 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://docs.xplorpay.com/quick-starts/ios-framework.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.
