Внедрение Google AdMob в SwiftUI - PullRequest
       41

Внедрение Google AdMob в SwiftUI

0 голосов
/ 17 октября 2019

Я пытаюсь интегрировать промежуточную рекламу в 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)
        }

    }

}

1 Ответ

0 голосов
/ 23 октября 2019

Рекомендую видео KAVSOFT

https://www.youtube.com/watch?v=HztdhFFJ96I

...