Swift

Bridging

To communicate with Tappx SDK we need a .h file acting as bridge between both languages.

Here you have the steps to do it. If you have .h file created and configured please jump to the next guide step.

Create a Header file where you will add the #imports from the headers.Go to Build Settings>Swift Compiler – Code Generation

In Objective-C Bridging Header, set the path and file name as here:

Bridging_swift_bridging_1.png

If you have created and configured the Bridging in your project, now you can add with Objective-C code the import:

#import <TappxFramework/TappxAds.h>

Using the SDK

Once integrated the SDK, you are ready to start using it!
Tappx App Key: First of all, you need to create a Tappx account on our website(http://www.tappx.com) and create an APP in the "My Apps" section. Once created, you will receive an App KEY that you will need in order to request ads. There is one App KEY for each app and operating system, so if you have apps with more than one operating system, you will need to create one app for each.
Tappx initialization
In the AppDelegate file of the Project add the lines in yellow from the following example:

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?
    func application(application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
        // Override point for customization after application launch.
        TappxFramework.addTappxKey("**YOUR-APP-KEY**")
        return true
    }
}

Interstitials

Interstitial is an ad shown in fullscreen, with the option to close it.
Now you need to initialize the Interstitial in the ViewController.swift file.

Example:

import UIKit

class ViewController: UIViewController
{
    var tappxInterstitial: TappxInterstitialViewController?
    override func viewDidLoad() {
        super.viewDidLoad()
        self.tappxInterstitial = TappxInterstitialViewController(delegate: self)
        self.tappxInterstitial?.setAutoShowWhenReady(true)
        self.tappxInterstitial?.load()
    }
}

extension ViewController: TappxInterstitialViewControllerDelegate {

    func presentViewController() -> UIViewController! {
        return self;
    }
}

If you want to request an interstitial to be shown as soon as it be ready, can use this method:

self.tappxInterstitial?.setAutoShowWhenReady(true)

If you want to have more control, you can use the following three options: load, isReady and show.

load is the request to get the ad and load all the information so you can show the ad.

self.tappxInterstitial?.load()

isReady allows you to check if the ad is ready to be shown. You will receive a "true" if the ad is ready and a "false" if not.

self.tappxInterstitial?.isReady

show allows you to display the interstitial ad that has loaded previously.

self.tappxInterstitial?.show()

These three options are useful in games for example, if you want to load the ad while the user is playing and show it immediately when the user finishes the play.

Delegates

You can add listener events into the Interstitial to be notified when a specific event happens in the ad. Here you have examples:

extension AdViewController: TappxInterstitialViewControllerDelegate {
   func tappxInterstitialViewControllerDidFinishLoad(_ viewController: TappxInterstitialViewController!) {
      print("INTERSTITIAL: FinishLoad")
   }
   func tappxInterstitialViewControllerDidFail(viewController: TappxInterstitialViewController!, withError error: Error!) {
      print("INTERSTITIAL: Failed %@", error.localizedDescription)
   }
   func tappxInterstitialViewControllerDidPress(_ viewController: TappxInterstitialViewController!) {
      print("INTERSTITIAL: DidPress")
   }
   func tappxInterstitialViewControllerDidClose(_ viewController: TappxInterstitialViewController!) {
      print("INTERSTITIAL: DidClose")
   }
   func tappxInterstitialViewControllerDidAppear(_ viewController: TappxInterstitialViewController!) {
      print("INTERSTITIAL: DidAppear")
   }
}

Additional information in the requests (interstitials and banners)
When you send a request (for banner or interstitial), we recommend to send additional information to get better results (earnings or downloads). It’s as easy as adding a parameter of the AdRequest type when you use the load method.
It’s not necessary to add all the information, but the more information you send, the better results you will get.

Example:

//For interstitials
let setting = TappxSettings()
setting.setAge(25)
setting.setGender(TappxGender.male)
setting.setMarital(TappxMarital.single)
setting.setYearOfBirth(1986)
self.tappxInterstitial?.load(setting)

//For banners
let setting = TappxSettings()
setting.setAge(40)
setting.setGender(TappxGender.female)
setting.setMarital(TappxMarital.single)
setting.setYearOfBirth(1986)
self.tappxBanner?.load(setting)

Tappx © 2020