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
- Option 1: Cocoapods
- Option 2: Manual Integration
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.
And you should be all set!
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
Download the SDK Zip containing the xcframework:
You can refer to this guide on how to include xcframework into your project
After implementing it you can proceed to the next step and add some code.
AttracktSDK
You can refer to this guide on how to include xcframework into your project
After implementing it you can proceed to the next step and add some code.
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
- Swift
- Objective C
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)
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 calledAttracktDelegate
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()
Import the SDK
Attrackt is a swift module so it should be imported with the @import and not #import command.@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
[AttracktIO startWithApiKey:@"THIS_IS_YOUR_APP_API_KEY_FROM_DASHBOARD" environment:AttracktEnvironmentProduction delegate:nil adsDelegate:nil];
Then you can always call from everywhere else on your app to implement the delegate:
Setting delegate not from init
[AttracktIO setDelegate:self];
Attrackt Instance can be accessed through the Class name
AttracktIO
Delegates
Attrackt SDK have the delegate calledAttracktDelegate
It can be implemented in the following way:
@interface ViewController : UIViewController<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
- (void)onAttracktErrorWithError:(AttracktError * _Nonnull)error
Attrackt was loaded successfully including the mediation 3rd party advertisers and ready to load an Ad
- (void)onAttracktSdkInitSuccess
After calling the loadAd function this delegate tells you that Attrackt is ready to play an Ad
- (void)onAttracktReadyToPlayAd