> For the complete documentation index, see [llms.txt](https://docs.ayetstudios.com/v/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ayetstudios.com/v/product-docs/offerwall/sdk-integrations-deprecated/ios-sdk.md).

# iOS SDK

The iOS SDK allows you to easily monetize your app and reward your users with in-app currency. Your users get access to our offerwalls, allowing them to earn currency for completing offers.

{% hint style="info" %}

### Updates History

**2024-08-02: v1.7.2** - Updated documentation to replace plist.info new Xcode 13 Info settings, and add up-to-date Xcode screenshots.

**2020-08-11: v1.7.1** - Updated documentation to introduce new parameters to differentiate chargebacks from conversions&#x20;

**2020-07-29: v1.7** - Updated iOS SDK to xcframework, support for Xcode 12, Swift 5.x, iOS 11+, dropped ARMv7 support&#x20;

**2019-10-20: v1.6** - Updated iOS SDK to Xcode 11, iOS 13 SDK, Swift 5.1, full binary support&#x20;

**2019-07-19: v1.5** - Updated iOS SDK with adslot changes, recompiled with Swift 5, re-added x86\_64 (simulator) support&#x20;

**2018-09-29: v1.4.2** - Updated iOS SDK to Xcode 10 and Swift 4.2, stripped debug symbols&#x20;

**2018-07-09: v1.4.1** - Removed Simulator Code from iOS SDK, fixed iTunes validation issues with Xcode 9+&#x20;

**2018-05-07: v1.4** - Framework recompiled with Swift 4.1&#x20;

**2018-03-08: v1.3** - You are able to use logs now in order to locate implementation problems&#x20;

**2018-01-20: v1.2** - Added functions that provide current user balances&#x20;

**2017-12-06: v1.0** - Initial Release of our Publisher SDK (iOS)
{% endhint %}

## Eligible Placement & AdSlot Combinations <a href="#eligible-placement-and-adslot-combinations" id="eligible-placement-and-adslot-combinations"></a>

The below table shows all Placement & AdSlot Type combinations that allow you to utilize the Android SDK integration.

| Placement Type | AdSlot Type | Eligible Integration Type |
| -------------- | ----------- | ------------------------- |
| iOS App        | Offerwall   | iOS SDK                   |

{% hint style="danger" %}
If you integrate the iOS SDK while using a different Placement & AdSlot combination in the ayeT-Studios dashboard, you won't be able to initialize the Offerwall.
{% endhint %}

## Getting Started

Before you start with the integration, make sure you have:

* [x] Created an Adslot
* [x] Added a Placement
* [x] Added an AdSlot

You will find more details here:

{% content-ref url="/pages/W7CE6bNya8L7RoaXXY21" %}
[Dashboard Setup](/v/product-docs/dashboard-setup.md)
{% endcontent-ref %}

{% hint style="info" %}
Make sure to use the correct package name that you intend to use for your final app.

Or create a test placement with a different package name that matches the package name of your test app.

If package name of your placement and your actuall app don't match, you can't initialize the Offerwall.
{% endhint %}

## Download the Library

You can download the lastest version of our publisher library here:

{% file src="/files/80t56vv5APs1HC0FM72G" %}

## Add the library to your Xcode project <a href="#add-the-library-to-your-xcode-project" id="add-the-library-to-your-xcode-project"></a>

Unzip the downloaded xcframework archive file, preferably somewhere in your project root.

Navigate to your project root in the Project Navigator, select **General** tab and then expand **Frameworks, Libraries, and Embedded Content**.

Click on the **+** sign and add the archive to your project (using select files), then make sure the Embed option is set to *Embed & Sign*. The final configuration should look like this:

<figure><img src="https://4086115684-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQYkbOrUvRXzrXgEDF9qs%2Fuploads%2F77gLBPYZIfAdEH3kxq1J%2FQzjCnMZ.png?alt=media&amp;token=23d6640b-6c78-442c-a472-78c0b36542ae" alt=""><figcaption></figcaption></figure>

Then, still in your project root in the Project Navigator, select **Info** tab and expand **Custom iOS Target Properties**. Right click and select **Add Row**, and add **App Transport Security Settings**. Then click on the newly added row, select **Add Row** again, and add the **Allow Arbitrary Loads** option. Make sure this is set to **YES**:

<figure><img src="https://4086115684-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQYkbOrUvRXzrXgEDF9qs%2Fuploads%2FWJ1YYW2EWVlu63NNuZsK%2FpT3Xgtk.png?alt=media&amp;token=cf278e4f-4c6a-46df-a85e-729398f6931f" alt=""><figcaption></figcaption></figure>

## Initialize the SDK & Managed User Balances <a href="#initialize-the-sdk-and-managed-user-balances" id="initialize-the-sdk-and-managed-user-balances"></a>

You'll need to initialize ayeT SDK before being able to use it. A good place to do this is the application:didFinishLaunchingWithOptions: method in your application delegate:

```swift
import AyetStudiosSDK
[...]
AyetSdk.sdkInit(appKey: "<your placement identifier from our dashboard>" , userIdentifier: "username (external identifier)" , callback: { available_currency , pending_currency , spent_currency in
    print("Available currency:  \(available_currency)")
    print("Pending currency:    \(pending_currency)")
    print("Spent currency:      \(spent_currency)")
});
```

If you want to spend user currency, for example if the user clicks a button assigned to a **purchaseInAppItem** function, you can utilize the **deductBalance** function:

```swift
@IBAction func purchaseInAppItem(_ sender: Any) {

    let deductAmount = 5

    AyetSdk.deductBalance(amount: deductAmount , deductCallback: {callback in

        if (callback.caseInsensitiveCompare("success") == .orderedSame) {
            print("Deduct response is successful");
            // TODO: activate the purchased content
        }
        else {
            print("Deduct response is unsuccessful");
            // this usually means that the user does not have sufficient balance in his account
        }
    })

}	         
```

{% hint style="info" %}
The status string will be "success" if the balance deduction was successful or "failed" if something went wrong (e.g. insufficient user balance).
{% endhint %}

{% hint style="warning" %}
**Attention:** The username or external identifier passed in the init call (e.g. username, hashed email address, etc.) will be accessible in the conversion callbacks through the *{external\_identifier}* parameter.
{% endhint %}

## Check User Balances (Managed Currency Handling) <a href="#check-user-balances-managed-currency-handling" id="check-user-balances-managed-currency-handling"></a>

After initializing the SDK, you can check the current user balances anywhere in your code:

```swift
AyetSdk.getAvailableCurrency();

AyetSdk.getPendingCurrency();

AyetSdk.getSpentCurrency();	  
```

## Show the Offerwall

Showing the offerwall is straight-forward, you can simply call **showOfferwall** from your UIViewController:

```swift
/AyetSdk.showOfferwall(currentController: self, adslotName: "my offerwall adslot name");	  
```

{% hint style="info" %}
**showOfferwall** starts our offerwall activity for the given adslot and displays available tasks for the user to complete.
{% endhint %}

## Logs

If you want to see logs in Xcode debug area, simply call **sdkLogEnable** before initializing sdk.

```swift
AyetSdk.sdkLogEnable();	  
```

## Conversion Callbacks & Currency Handling <a href="#conversion-callbacks-and-currency-handling" id="conversion-callbacks-and-currency-handling"></a>

Learn about:

* Setting up callbacks
* IP Whitelists
* Securing callbacks using HMAC Security Hash
* Testing callbacks

Click on the link below:

{% content-ref url="/pages/5sxVWIW1fto5Mmv1JxeJ" %}
[Callbacks & Testing](/v/product-docs/callbacks-and-testing.md)
{% endcontent-ref %}
