Integrating AdHesion Ad - adform/adform-ios-sdk GitHub Wiki

Basic Adhesion Ad Implementation

AFAdHesion class is a subclass of AFAdInline and is used to provide sticky banners. Therefore, this ad placement type has all the controls as an inline ad. The main difference between AFAdInline and AFAdHesion is that adhesion ads are always visible and are placed at the top or bottom of the application screen, unlike inline ads that are placed inside the application content and may be hidden (in case of scrolling content). AFAdHesion view takes care of positioning itself in superview, e.g. avoid being hidden under navigation or toolbars. To use adhesion ads you just have to create a new AFAdHesion object set its position and start loading.

Available positions:

  • AFAdPositionTop - Ad view is positioned at the top of superview, centered.
  • AFAdPositionBottom - Ad view is positioned at the bottom of superview, centered.
  • AFAdPositionDefault - Default ad view position equals AFAdPositionBottom position.

AFAdHesion implementation example.

Close button

AdHesion ads may have a close button at the top right corner. By default it is disabled, but you can enable the close button by setting showCloseButton property of the AFAdHesion view to true.

Autohide

The adHesion ad unit has an autohide feature. If enabled, the ad unit will disappear when a viewer interacts with the screen, e.g., during content scrolling or zooming, and reappear when the interaction ends. This feature is disabled by default, but you can enable it by setting hidesOnSwipe property to true.

Swift

//Create new ad view.
let adView = AFAdHesion(masterTagId: masterTag, position: .default, presenting: self)
        
//Add ad view to view hierarchy
view.addSubview(adView)
        
//Initiate ad loading.
adView.loadAd()
Objective-C
//Create new ad view.
AFAdHesion *adView = [[AFAdHesion alloc] initWithMasterTagId:mtag position:AFAdPositionDefault presentingViewController:self];

//Add ad view to view hierarchy
[self.view addSubview:adView];

//Initiate ad loading
[adView loadAd];

That's it, you have a sticky banner.

Important, setting AFAdHesion position (frame or layout constraints) manually may lead to undefined behavior.

Sample code:

For a complete example of how to integrate Adform Adhesion ads into your application, check out the sample app.

⚠️ **GitHub.com Fallback** ⚠️