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
BannerStateinstance is provided.Declaration
Swift
@MainActor public init(state: BannerState)Parameters
stateThe banner state containing size and request.
-
Declaration
Swift
@MainActor public var body: some View { get }
-
Called when the banner is successfully loaded.
Declaration
Swift
@MainActor func onAdLoad(_ action: @escaping (AdInfo?) -> Void) -> BannerParameters
actionClosure receiving ad metadata, or
nilif unavailable. -
Called when the banner fails to load.
Declaration
Swift
@MainActor func onAdFailure(_ action: @escaping (Error) -> Void) -> BannerParameters
actionClosure 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) -> BannerParameters
actionClosure receiving impression-level revenue data, or
nilif unavailable.