Last active
March 15, 2022 03:45
-
-
Save MichaelBarney/af66902172cb5d595795b5633522fc71 to your computer and use it in GitHub Desktop.
A google AdMob Banner implementation in SwiftUI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import SwiftUI | |
| import GoogleMobileAds | |
| import UIKit | |
| final class Interstitial:NSObject, GADInterstitialDelegate{ | |
| var interstitial:GADInterstitial = GADInterstitial(adUnitID: interstitialID) | |
| override init() { | |
| super.init() | |
| LoadInterstitial() | |
| } | |
| func LoadInterstitial(){ | |
| let req = GADRequest() | |
| self.interstitial.load(req) | |
| self.interstitial.delegate = self | |
| } | |
| func showAd(){ | |
| if self.interstitial.isReady{ | |
| let root = UIApplication.shared.windows.first?.rootViewController | |
| self.interstitial.present(fromRootViewController: root!) | |
| } | |
| else{ | |
| print("Not Ready") | |
| } | |
| } | |
| func interstitialDidDismissScreen(_ ad: GADInterstitial) { | |
| self.interstitial = GADInterstitial(adUnitID: interstitialID) | |
| LoadInterstitial() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment