Overview
Display backfill ads in your WKWebView by registering it with the Adrop SDK. This allows web content within your app to show ads through the Adrop platform.
Info.plist Configuration
Add the following key to your Info.plist to enable backfill ads in WebView:
<key>GADIntegrationManager</key>
<string>webview</string>
This configuration is required for backfill ads to work properly in WebView. Without it, backfill ads may not display.
Register WebView
import WebKit
import AdropAds
class WebViewController: UIViewController {
@IBOutlet weak var webView: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
// Initialize a WKWebViewConfiguration object.
let webViewConfiguration = WKWebViewConfiguration()
// Let HTML videos with a "playsinline" attribute play inline.
webViewConfiguration.allowsInlineMediaPlayback = true
// Let HTML videos with an "autoplay" attribute play automatically.
webViewConfiguration.mediaTypesRequiringUserActionForPlayback = []
// Initialize the WKWebView with your WKWebViewConfiguration object.
webView = WKWebView(frame: view.frame, configuration: webViewConfiguration)
// Register WebView for backfill ads support
// Call as early as possible, before loading content
Adrop.registerWebView(webView)
// Load your web content
if let url = URL(string: "https://your-website.com") {
webView.load(URLRequest(url: url))
}
}
}
registerWebView() must be called on the main thread.
Call this method as early as possible (e.g., in viewDidLoad), before loading any web content.
Backfill ads in WebView requires adrop-ads-backfill module. If the module is not installed, registerWebView() is silently ignored.