Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find type 'GADInterstitial' in scope?

I just upgraded Google Mobile Ads SDK to version 8.0, but I am getting this error:

Cannot find type 'GADInterstitial' in scope

I also added this code to AppDelegate:

GADMobileAds.sharedInstance().start(completionHandler: nil)

Google Mobile Ads SDK worked perfectly until I upgraded to version 8.0

Note: I also use Firebase Framework in my app.

like image 615
Besart Avatar asked Feb 16 '21 14:02

Besart


1 Answers

Here this is the code of Admob Interstitial only copy and paste I just upgraded Google Mobile Ads SDK to version 8.0

import GoogleMobileAds

class ViewController: UIViewController,GADFullScreenContentDelegate{
    
private var interstitial: GADInterstitialAd?
    
override func viewDidLoad() {
    super.viewDidLoad()
    
    let request = GADRequest()
        GADInterstitialAd.load(withAdUnitID:"ca-app-pub-3940256099942544/4411468910",request: request,
        completionHandler: { [self] ad, error in
          if let error = error {
             return
             }
             interstitial = ad
             interstitial?.fullScreenContentDelegate = self
            }
        )
}

 func ad(_ ad: GADFullScreenPresentingAd, didFailToPresentFullScreenContentWithError error: Error) {
   print("Ad did fail to present full screen content.")
 }

 func adDidPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) {
   print("Ad did present full screen content.")
 }

 func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) {
   print("Ad did dismiss full screen content.")
 }   

@IBAction func AddAction(_ sender: UIButton) {        
    if interstitial != nil {
        interstitial.present(fromRootViewController: self)
      } else {
        print("Ad wasn't ready")
      }
}         

}

like image 79
M Hamayun zeb Avatar answered Sep 22 '22 01:09

M Hamayun zeb