Skip to main content

Media Native Placement

Media Native renders the same video and display creatives as the Media format, but inside a layout you build and control instead of the SDK's own container. The SDK still owns the paid click, the same as Media.


Sample App

The official Teads SDK sample application includes working examples of this format. Use it for implementation examples and as a reference while you set up this placement.

Teads iOS Sample App on GitHub

Example​

import UIKit
import TeadsSDK

class NativeAdViewController: UIViewController {

private var nativePlacement: TeadsAdPlacementMediaNative?
private var nativeAdView: TeadsNativeAdView?

override func viewDidLoad() {
super.viewDidLoad()
setupNativeAd()
}

private func setupNativeAd() {
// Create custom native ad view
nativeAdView = createCustomNativeAdView()

// Create configuration
let config = TeadsAdPlacementMediaConfig(
pid: 124859,
articleUrl: URL(string: "https://example.com/article/123")
)

// Create placement
nativePlacement = TeadsAdPlacementMediaNative(config, delegate: self)

// Load and bind the ad
do {
let binder = try nativePlacement?.loadAd()

if let nativeAdView = nativeAdView {
binder?(nativeAdView)
addNativeAdToView(nativeAdView)
}
} catch {
print("Failed to load native ad: \(error)")
}
}

private func createCustomNativeAdView() -> TeadsNativeAdView {
// Create your custom native ad view
// This can be designed in Interface Builder or programmatically
let adView = TeadsNativeAdView(frame: .zero)

// Customize the appearance to match your app
adView.backgroundColor = .systemBackground
adView.layer.cornerRadius = 12
adView.layer.shadowColor = UIColor.black.cgColor
adView.layer.shadowOpacity = 0.1
adView.layer.shadowRadius = 8

return adView
}

private func addNativeAdToView(_ adView: UIView) {
view.addSubview(adView)

adView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
adView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 16),
adView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -16),
adView.centerYAnchor.constraint(equalTo: view.centerYAnchor),
adView.heightAnchor.constraint(equalToConstant: 250)
])
}
}

Ad Lifecycle Listener​

Implement TeadsAdPlacementEventsDelegate to observe playback, clicks, and viewability. See Placement Events Listener for the full event reference and error handling guide.

Checklist​