SwiftUI中的Google AdMob插页式

问题描述 投票:0回答:1

我尝试将非页内广告整合到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)
        }

    }

}
admob integration swiftui interstitial
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.