Question

Is this code correct to implement an interstitial ad?

enter image description here

Because when I launch it I get this,

<Google> Cannot present interstitial.  It is not ready.
Was it helpful?

Solution

You need to wait until the ad loads successfully and only then present it in case of Interstitial ads. Otherwise the ads wont show up.

To do this conform to the GADInterstitialDelegate protocol and set your view controller as the delegate of interstitial_.

interstitial_.delegate = self;

Then implement interstitialDidReceiveAd as follows.

- (void)interstitialDidReceiveAd:(GADInterstitial *)ad
{
    [interstitial_ presentFromRootViewController:self];
}

For more reference, please check Interstitials ads

OTHER TIPS

Swift 3.0

in viewDidLoad() or createAndLoadInterstitial()

interstitial.delegate = self

then implement

func interstitialDidReceiveAd(_ ad: GADInterstitial) {
    interstitial.present(fromRootViewController: self)
}

If you want load google interstitial ads again on next page or current page use below code..

//On view Did load add following line on your next page or current page view controller.m

self.interstitial = [self createAndLoadInterstitial];

//create following methods on your next page or current page view controller.m

- (GADInterstitial *)createAndLoadInterstitial {
    GADInterstitial *interstitial = [[GADInterstitial alloc] initWithAdUnitID:@"ca-app-pub-3940256099942544/4411468910"];
    interstitial.delegate = self;
    [interstitial loadRequest:[GADRequest request]];
    return interstitial;
}
- (void)interstitialDidReceiveAd:(GADInterstitial *)ad
{
    [self.interstitial presentFromRootViewController:self];
}
- (void)interstitialDidDismissScreen:(GADInterstitial *)interstitial 
{
//leave this method as empty    
}

now you will able to receive ads will shown

I don't think you have to use interstitialDidReceiveAd method. This is not recommended by admob documentation. Maybe you can use DispatchQueue.main.async in viewDidLoad()

if (mInterstitialAd.isReady)
{
    DispatchQueue.main.async
    {
        mInterstitialAd.present(fromRootViewController: self)
    }
}

Swift 5.0

in viewDidLoad()

Make sure to set the delegate for your View Controller by doing so

interstitial.delegate = self

then in the delegate methods you could implement the following

func interstitialDidReceiveAd(_ ad: GADInterstitial) {
    interstitial.present(fromRootViewController: self)
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top