Skip to main content

Overview

Native ads are ad formats that naturally integrate with your app’s UI. You can freely customize ad elements (title, image, description, etc.) to match your app design.

Key Features

  • Custom design that perfectly integrates with app UI
  • Individual access and placement of ad elements
  • Option to display advertiser profile information
  • Support for additional custom fields

Implementation Steps

Native ad implementation proceeds in the following steps:
  1. Load ad
  2. Create custom view
  3. Bind view
  4. Handle delegates

1. Load Ad

Create an AdropNativeAd instance and load the ad.
import AdropAds

class MyViewController: UIViewController {
    private var nativeAd: AdropNativeAd?

    override func viewDidLoad() {
        super.viewDidLoad()

        // Create native ad
        nativeAd = AdropNativeAd(unitId: "YOUR_NATIVE_UNIT_ID")
        nativeAd?.delegate = self

        // Load ad
        nativeAd?.load()
    }
}

Set Context ID

You can set a Context ID for contextual targeting.
// contextId is read-only — set via initializer
let nativeAd = AdropNativeAd(unitId: "YOUR_UNIT_ID", contextId: "article_123")
Use test unit IDs during development. See the Test Unit IDs section.

2. Create Custom View

Compose your native ad view using Storyboard or code.

UIKit (Storyboard/XIB)

Create AdropNativeAdView in Storyboard and connect ad elements as IBOutlets.
import AdropAds

class NativeAdViewCell: UITableViewCell {
    @IBOutlet weak var nativeAdView: AdropNativeAdView!
    @IBOutlet weak var iconImageView: UIImageView!
    @IBOutlet weak var headlineLabel: UILabel!
    @IBOutlet weak var bodyLabel: UILabel!
    @IBOutlet weak var mediaView: UIView!
    @IBOutlet weak var callToActionButton: UIButton!

    // Advertiser profile (optional)
    @IBOutlet weak var advertiserLogoImageView: UIImageView!
    @IBOutlet weak var advertiserNameLabel: UILabel!

    func configure(with ad: AdropNativeAd) {
        // View binding (see next section)
    }
}

UIKit (Code)

import AdropAds

class NativeAdView: UIView {
    let nativeAdView = AdropNativeAdView()
    let iconImageView = UIImageView()
    let headlineLabel = UILabel()
    let bodyLabel = UILabel()
    let mediaView = UIView()
    let callToActionButton = UIButton()

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupViews()
    }

    private func setupViews() {
        addSubview(nativeAdView)
        nativeAdView.addSubview(iconImageView)
        nativeAdView.addSubview(headlineLabel)
        nativeAdView.addSubview(bodyLabel)
        nativeAdView.addSubview(mediaView)
        nativeAdView.addSubview(callToActionButton)

        // Auto Layout setup
        // ...
    }
}

3. Bind View

Bind ad elements to AdropNativeAdView to display ad data.
func configure(with ad: AdropNativeAd) {
    // Bind each element to AdropNativeAdView
    nativeAdView.setIconView(iconImageView)
    nativeAdView.setHeadLineView(headlineLabel)
    nativeAdView.setBodyView(bodyLabel)
    nativeAdView.setMediaView(mediaView)
    nativeAdView.setCallToActionView(callToActionButton)

    // Advertiser profile (optional)
    if let advertiserLogoView = advertiserLogoImageView,
       let advertiserNameView = advertiserNameLabel {
        nativeAdView.setProfileLogoView(advertiserLogoView)
        nativeAdView.setProfileNameView(advertiserNameView)
    }

    // Set ad data (automatically displayed in bound views)
    nativeAdView.setNativeAd(ad)
}

Binding Methods

MethodDescriptionRequired
setIconView(_:onClick:)Set icon image view. onClick: ((AdropNativeAd?, UIView) -> Void)? = nilOptional
setHeadLineView(_:onClick:)Set title label. onClick: ((AdropNativeAd?, UIView) -> Void)? = nilOptional
setBodyView(_:)Set description labelOptional
setMediaView(_:)Set main image/video viewOptional
setCallToActionView(_:onClick:)Set CTA button. onClick: ((AdropNativeAd?, UIView) -> Void)? = nilOptional
setAdvertiserView(_:onClick:)Set advertiser view. onClick: ((AdropNativeAd?, UIView) -> Void)? = nilOptional
setProfileLogoView(_:onClick:)Set advertiser logo image view. onClick: ((AdropNativeAd?, UIView) -> Void)? = nilOptional
setProfileNameView(_:onClick:)Set advertiser name label. onClick: ((AdropNativeAd?, UIView) -> Void)? = nilOptional
setNativeAd(_:)Set ad dataRequired
The onClick closure is called when the user taps the bound view. It receives the current AdropNativeAd? instance and the tapped UIView as parameters. If not provided, the default click behavior (opening the destination URL) is used.
To display advertiser profile, you must enable Show Advertiser Profile for the ad unit in Ad Control Console.

4. Handle Delegates

Implement AdropNativeAdDelegate to handle ad events.
extension MyViewController: AdropNativeAdDelegate {
    // Ad received successfully
    func onAdReceived(_ nativeAd: AdropNativeAd) {
        print("Native ad received successfully")

        // Access ad data (properties are non-optional)
        print("Title: \(nativeAd.headline)")
        print("Description: \(nativeAd.body)")
        print("CTA: \(nativeAd.callToAction)")

        // Bind ad to view
        configureNativeAdView(with: nativeAd)
    }

    // Ad receive failed
    func onAdFailedToReceive(_ nativeAd: AdropNativeAd, _ errorCode: AdropErrorCode) {
        print("Native ad failed to receive: \(errorCode)")
    }

    // Ad clicked (optional)
    func onAdClicked(_ nativeAd: AdropNativeAd) {
        print("Native ad clicked")
    }

    // Ad impression (optional)
    func onAdImpression(_ nativeAd: AdropNativeAd) {
        print("Native ad impression")
    }
}

Delegate Methods

MethodRequiredDescription
onAdReceived(_:)RequiredCalled when ad loads successfully
onAdFailedToReceive(_:_:)RequiredCalled when ad fails to load
onAdClicked(_:)OptionalCalled when user clicks the ad
onAdImpression(_:)OptionalCalled when ad is displayed

Closure Callbacks

As an alternative to delegates, you can use closure-based callbacks.
let nativeAd = AdropNativeAd(unitId: "YOUR_UNIT_ID")

nativeAd.onAdReceived = { ad in
    print("Native ad received")
}

nativeAd.onAdFailedToReceive = { ad, errorCode in
    print("Native ad failed: \(errorCode)")
}

nativeAd.onAdImpression = { ad in
    print("Native ad impression")
}

nativeAd.onAdClicked = { ad in
    print("Native ad clicked")
}
If both a delegate and closures are set, both will be called.

Ad Properties

You can access ad data through the AdropNativeAd object.

Basic Properties

// When ad is received successfully
func onAdReceived(_ nativeAd: AdropNativeAd) {
    // Title
    print("Title: \(nativeAd.headline)")

    // Description
    print("Description: \(nativeAd.body)")

    // CTA button text
    print("CTA: \(nativeAd.callToAction)")

    // Main image/video
    print("Media URL: \(nativeAd.asset)")
}

Advertiser Profile

// Advertiser information (profile and its properties are non-optional)
let profile = nativeAd.profile
print("Advertiser logo: \(profile.displayLogo)")
print("Advertiser name: \(profile.displayName)")

// Profile link (optional — links to the advertiser's page)
if let link = profile.link {
    print("Profile link: \(link)")
}

Custom Fields

You can access additional text items set in Ad Control Console.
// Additional text items (extra is non-optional [String: String])
let extra = nativeAd.extra
if !extra.isEmpty {
    // Example: Price information
    if let price = extra["price"] {
        print("Price: \(price)")
    }

    // Example: Discount rate
    if let discount = extra["discount"] {
        print("Discount: \(discount)")
    }

    // Example: Rating
    if let rating = extra["rating"] {
        print("Rating: \(rating)")
    }
}
The extra field uses additional text item IDs defined in the ad unit settings in Ad Control Console as keys.

Property List

PropertyTypeDescription
unitIdStringAd unit ID
contextIdStringContext ID for contextual targeting
headlineStringAd title
bodyStringAd description
callToActionStringCTA button text
iconStringIcon image URL
coverStringCover image URL
assetStringMain image/video URL
creativeStringCreative HTML content
creativeSizeCGSizeCreative content size
advertiserStringAdvertiser name
advertiserURLStringAdvertiser URL
profileAdropNativeAdProfileAdvertiser profile information
extra[String: String]Additional custom fields
accountTag[String: Any]Account-level tag data
creativeTag[String: Any]Creative-level tag data
destinationURLString?Ad destination URL
txIdStringTransaction ID
campaignIdStringCampaign ID
creativeIdStringCreative ID
browserTargetBrowserTarget?How to open URLs on ad click
isLoadedBoolWhether ad is loaded
isBackfilledBoolWhether ad is a backfill ad

AdropNativeAdProfile

PropertyTypeDescription
displayLogoStringAdvertiser logo image URL
displayNameStringAdvertiser display name
linkString?Link to the advertiser’s page

Custom Click

You can use Custom Click to handle ad click behavior yourself instead of using the default behavior (opening the destination URL).

Setup

let nativeAd = AdropNativeAd(unitId: "YOUR_UNIT_ID")
nativeAd.useCustomClick = true

Entire Click Area

Use setIsEntireClick(_:) to make the entire AdropNativeAdView clickable.
nativeAdView.setIsEntireClick(true)
When useCustomClick is true, setIsEntireClick(true) is automatically called in setNativeAd(_:).

Manual Click

Use performClick() to manually trigger a click event.
nativeAdView.performClick()

Open URL

Use open(_:useInAppBrowser:) to open a URL programmatically.
// Open destination URL
nativeAd.open(nativeAd.destinationURL)

// Open in in-app browser
nativeAd.open(nativeAd.destinationURL, useInAppBrowser: true)

Best Practices

Error Handling

Display fallback UI when ad fails to load to maintain user experience.
func onAdFailedToReceive(_ nativeAd: AdropNativeAd, _ errorCode: AdropErrorCode) {
    print("Native ad failed to receive: \(errorCode)")

    // Hide ad area
    nativeAdContainerView.isHidden = true

    // Or display fallback content
    showFallbackContent()
}

Test Unit IDs

Use the following test unit IDs during development and testing.
Ad TypeTest Unit ID
Native (Image)PUBLIC_TEST_UNIT_ID_NATIVE
Native Video (16:9)PUBLIC_TEST_UNIT_ID_NATIVE_VIDEO_16_9
Native Video (9:16)PUBLIC_TEST_UNIT_ID_NATIVE_VIDEO_9_16
// Load test ad
nativeAd = AdropNativeAd(unitId: AdropUnitId.PUBLIC_TEST_UNIT_ID_NATIVE)
Make sure to use actual unit IDs created in Ad Control Console for production deployment.

Backfill Ads

When backfill ads are enabled, backfill ads are automatically loaded when direct ads are unavailable. Use the isBackfilled property to check if the ad is a backfill ad.
class ViewController: UIViewController, AdropNativeAdDelegate {
    private var nativeAd: AdropNativeAd?

    func onAdReceived(_ nativeAd: AdropNativeAd) {
        if nativeAd.isBackfilled {
            print("Backfill ad loaded")
        } else {
            print("Direct ad loaded")
        }
    }

    func onAdFailedToReceive(_ nativeAd: AdropNativeAd, _ errorCode: AdropErrorCode) {
        switch errorCode {
        case .ERROR_CODE_AD_NO_FILL:
            print("No direct ad, requesting backfill...")
        case .ERROR_CODE_AD_BACKFILL_NO_FILL:
            print("No backfill ad available")
            // Hide ad area
        default:
            print("Ad load failed: \(errorCode)")
        }
    }
}
To use backfill ads, add the AdropAds-Backfill dependency. See Getting Started.

Getting Started

SDK installation and initialization

Banner Ads

Implementing banner ads

Interstitial Ads

Implementing interstitial ads

Rewarded Ads

Implementing rewarded ads