Skip to main content

Integrate Attrackt SDK for iOS

Here you will find the guide to implement and use the Attrackt iOS Framework SDK

Before You Begin

Make sure you meet the following requirements

Requirements

  • The integration requires Attrackt account, so create account if you haven’t already done so, and create a new iOS app in your account. Refer to the Add Your Apps and Placements section of our Using the Publisher Dashboard article to learn how to set up placements in the Attrackt dashboard.
  • Attrackt iOS SDK v.1.0.0 supports Xcode 13.
  • Attrackt iOS SDK v.1.0.0 is fully compatible with the latest iOS version (iOS 15 as of the release date) and supports 64-bit apps.
  • Attrackt iOS SDK v.1.0.0 supports applications that run on iOS 12 and higher. We do not recommend integrating the SDK for iOS versions lower than 12.0.

Step 1. Add the Attrackt Framework to Your Xcode Project

Attrackt SDK can be installed via the CocoaPods dependency manager
To make it work just implement the required Pod line into your application main Podfile.

Attrackt SDK Main pod.

pod 'Attrackt'


Example Pod file

platform :ios, '12.0'

target 'AttracktIntegrationTest' do

  use_frameworks!
  pod 'Attrackt'

end

Don't forget to run Pod Install

pod install --update-repo
And you should be all set!

Step 2. Add Code

Initialize the SDK

Attrackt is a Singleton SDK instance that can be called from everywhere in your application,
it is crash safe and thread safe so minimal interference to the hosting application.

To instantiate the SDK you can run the following code from your ViewController or AppDelegate

Import the SDK

import Attrackt

Init the SDK

In order to init the SDK we use the function named "Start". the function accepts multiple parameters:

- apiKey: String (required) This is the application API Key which you get after creating an app on dashboard
- environment: AttracktEnvironment (required) Set ENV Test or Production to mute log and show real ads
- delegate: AttracktDelegate (optional) The class reference that implements the delegate protocol and methods
- adsDelegate: AttracktAdsDelegate (optional) The class reference that implements the ads delegate protocol and methods

func start(apiKey: String, environment: AttracktEnvironment, delegate: AttracktDelegate? = nil, adsDelegate: AttracktAdsDelegate? = nil)
You can init without setting a delegate in case you would like to Init the sdk on your AppDelegate and get the AttracktDelegate methods implemented on another class

Then you can always call from everywhere else on your app to implement the delegate:

Setting delegate not from init
AttracktIO.setDelegate(delegate: self)

Attrackt Instance can be accessed through the Class name

AttracktIO

Example of init call
AttracktIO.start(apiKey: "THIS_IS_YOUR_APP_API_KEY_FROM_DASHBOARD", environment: .Production, delegate: self)



Delegates

Attrackt SDK have the delegate called

AttracktDelegate

It can be implemented in the following way:
class AppDelegate: UIResponder, UIApplicationDelegate, AttracktDelegate {

Delegate Methods

After calling the SDK init method, these functions will be called to present the state of the sdk.

Indicates that something went wrong with the initiation e.g bad Api Key. The error object will give the reason for faiilure
func onAttracktError(error: AttracktError)
Attrackt was loaded successfully including the mediation 3rd party advertisers and ready to load an Ad
func onAttracktSdkInitSuccess()
After calling the loadAd function this delegate tells you that Attrackt is ready to play an Ad
func onAttracktReadyToPlayAd()