To load a banner ad, first create a UIViewRepresentable object, a wrapper that lets you integrate BIDBannerView, a UIKit view type object, into your SwiftUI view hierarchy.
importbidappstructExampleSwiftUIWrapper:UIViewRepresentable{funcmakeUIView(context: Context) -> MAAdView {let adView = BIDBannerView.banner( with: BIDAdFormat.banner_320x50 as! BIDAdFormat, delegate: bannerDelegate) adView.delegate = context.coordinator// Set background or background color for banners to be fully functional adView.backgroundColor = BACKGROUND_COLORreturn adView }funcupdateUIView(_uiView: MAAdView, context: Context) {}funcmakeCoordinator() -> Coordinator {Coordinator() }}
Also, provide a custom Coordinator class for the wrapper object that conforms to BIDBannerViewDelegate so that you are notified of when your ad is ready and of other ad-related events. Inside the wrapper’s makeUIView method, create a BIDBannerView object.