Swift
Banners
A banners is a type of ad unit that occupies a spot of a specific size (320x50, 728x90 or 300x250) within your app's layout. This type of ad unit can not be hidden.
The available sizes (in dots) are the following:
- TappxBannerSizeSmartBanner: Is adjusted automatically inside the device screen. The sizes you can request are: 320x50 and 728x90.
- TappxBannerSize320x50: Standard Banner for phones.
- TappxBannerSize728x90: Standard Banner for tablets.
- TappxBannerSize300x250: Also known as Mrec. Is a rectangular banner for phones and tablets. Add to the ViewController.swift file the following lines:
import UIKit
class ViewController: UIViewController
{
var tappxBanner: TappxBannerViewController?
override func viewDidLoad() {
super.viewDidLoad()
self.tappxBanner = TappxBannerViewController(delegate: self, andSize: TappxBannerSize.smartBanner, andPosition: TappxBannerPosition.bottom)
self.tappxBanner?.load()
}
}
extension ViewController: TappxBannerViewControllerDelegate {
func presentViewController() -> UIViewController! {
return self;
}
}
Important: To get the best memory management you must destroy the banner once used. You can do it with these lines:
if self.tappxBanner != nil {
self.tappxBanner?.removeBanner()
self.tappxBanner = nil
}
Advanced Banner
If you want to show the ad in a different position than TOP or BOTTOM, there are two options:
Setting the exact position:
self.tappxBanner = TappxBannerViewController(delegate: self,
andSize: TappxBannerSize.smartBanner, andLocation: CGPoint(x: X, y: Y))
With an UIView:
self.tappxBanner = TappxBannerViewController(delegate: self,
andSize: TappxBannerSize.smartBanner, andView: self.bannerView)
Delegates
You can listen to the banner events with the "delegates" functions:
extension AdViewController: TappxBannerViewControllerDelegate {
func tappxBannerViewControllerDidFinishLoad(_ vc: TappxBannerViewController!) {
print("BANNER: FinishLoad")
}
func tappxBannerViewControllerDidFail(_ vc: TappxBannerViewController!, withError error: Error!) {
print("BANNER: Failed %@", error.localizedDescription)
}
func tappxBannerViewControllerDidPress(_ vc: TappxBannerViewController!) {
print("BANNER: DidPress")
}
func tappxBannerViewControllerDidClose(_ vc: TappxBannerViewController!) {
print("BANNER: DidClose")
}
}
Tappx © 2024