Skip to main content
The SDK presents ads with UIKit. VideoAdHost is a SwiftUI view that does the bridging: place it over your player, set its ad, and it shows. It is part of KontextVideoSDK; there is nothing else to add.

A player screen

Keep the player, the VideoAds and the ad on screen in a model the screen owns with @StateObject:

VideoAdHost

  • Setting the ad shows it. A loaded ad shows once the host is on screen with a size. Set nil, or another ad, and the one shown is dismissed; it is dismissed too when the host leaves the view hierarchy.
  • Every format. An overlay or pause ad shows where the host is placed. A linear ad is presented full screen from the top view controller of the host’s window; the host never dismisses it: it ends by itself or by the viewer, and onEnd still arrives.
  • The host is the ad’s delegate. Hear the ad through the host’s closures, not ad.delegate.
  • onShowFailed gets the reason show would throw: anotherAdShowing, contentPaused, containerTooSmall, …
  • An ad is tried once. After a failed show, passing the same ad again on later updates does nothing, so onShowFailed cannot loop with your view’s updates. To try it again, set nil (or another ad), then that ad.
  • Taps outside the ad go through to your player, so your own gestures keep working.

Keep the ads on the model

SwiftUI recreates view structs. Keep the VideoAds on your @StateObject model, not in the view: releasing a VideoAds ends its ads. Call ads.destroy() when the viewer actually leaves the episode (your back button, the next episode), not in onDisappear: a linear ad covers your view, and SwiftUI calls onDisappear for that too.

In a feed

Give each page its own model and host, and set the ad on the current page only. An ad on a page swiped away ends within about a second (.interrupted), freeing the screen for the next page’s ad. See Ads in a feed.