-
Go to Project Settings -> General -> Frameworks, Libraries, and Embedded Content:
-
Click on the + button and select Add Other... -> Add Package Dependency...:
-
On the search bar, type the URL of this repository:
https://github.com/CleverAdvertising/swift-ads-package.git
-
Add the following line to your
Podfile
:pod 'SwiftAdsPackage', '~> 1.0.8'
-
Run the following command to install the Swift Ads Package:
pod install
-
Create a file named AdsWebView.swift
-
Insert the following code
import Foundation
import SwiftUI
import WebKit
import swift_ads_package
import Combine
struct AdsWebView: UIViewRepresentable {
let scriptId: Int
func makeUIView(context: Context) -> WKWebView {
let webView = SwiftAdsPackage(frame: .zero, configuration: WKWebViewConfiguration(), scriptId: scriptId)
return webView
}
func updateUIView(_ uiView: WKWebView, context: Context) {
// Handle updates if necessary
}
}
- Add the following code anywhere in your project to display the ad
AdsWebView(scriptId: script id here).frame(width: 320, height: 50)