【发布时间】:2019-10-17 20:57:21
【问题描述】:
我尝试在 swiftUI 中集成插页式广告,我创建了 UIViewControllerRepresentable 类和 UIViewController。
https://developers.google.com/admob/ios/interstitial#show_the_ad
但我不知道在广告准备好并加载后如何展示广告。
在 Admob 文档中我有
if interstitial.isReady {
interstitial.present(fromRootViewController: viewController)
} else {
print("Ad wasn't ready")
}
但我不知道他的代码放在哪里以及如何在我的 swiftUI 视图中输入视图
import SwiftUI
import UIKit
import GoogleMobileAds
final class GADInterstitialViewController: UIViewControllerRepresentable {
public var interstitial: GADInterstitial!
public func makeUIViewController(context: UIViewControllerRepresentableContext<GADInterstitialViewController>) -> UIViewController {
let interstitial = GADInterstitial(adUnitID: "ca-app-pub-3940256099942544/4411468910")
let viewController = UIViewController()
let request = GADRequest()
interstitial.load(request)
return viewController
}
func updateUIViewController(_ uiViewController: UIViewController, context: UIViewControllerRepresentableContext<GADInterstitialViewController>) {
}
}
struct Transit: View {
var body: some View {
ZStack{
GADInterstitialViewController()
.frame(width: screen.width, height: screen.height, alignment: .center)
}
}
}
【问题讨论】:
-
您可以在这里找到横幅广告和插页式广告的实现medium.com/@michaelbarneyjr/…
标签: admob integration swiftui interstitial