Banner

@MainActor
public struct Banner : View

A SwiftUI view that displays a banner ad.

@State private var bannerState: BannerState?
@State private var isLoaded = false

if let bannerState {
    Banner(state: bannerState)
        .onAdLoad { _ in isLoaded = true }
        .onAdFailure { _ in isLoaded = false }
        .opacity(isLoaded ? 1 : 0)
}

Button("Load") {
    bannerState = BannerState(size: .sticky(), request: AdRequest(adUnitID: "R-M-XXXXXX-Y"))
}
  • Creates a banner view. Loading starts immediately when the view appears. A new load is triggered each time a new BannerState instance is provided.

    Declaration

    Swift

    @MainActor
    public init(state: BannerState)

    Parameters

    state

    The banner state containing size and request.

  • Declaration

    Swift

    @MainActor
    public var body: some View { get }

Event callbacks

  • Called when the banner is successfully loaded.

    Declaration

    Swift

    @MainActor
    func onAdLoad(_ action: @escaping (AdInfo?) -> Void) -> Banner

    Parameters

    action

    Closure receiving ad metadata, or nil if unavailable.

  • Called when the banner fails to load.

    Declaration

    Swift

    @MainActor
    func onAdFailure(_ action: @escaping (Error) -> Void) -> Banner

    Parameters

    action

    Closure receiving the load error.

  • Called when the user taps the banner.

    Declaration

    Swift

    @MainActor
    func onAdClick(_ action: @escaping () -> Void) -> Banner
  • Called when an impression is tracked.

    Declaration

    Swift

    @MainActor
    func onAdImpression(_ action: @escaping (ImpressionData?) -> Void) -> Banner

    Parameters

    action

    Closure receiving impression-level revenue data, or nil if unavailable.