Reputation:
Is this code correct to implement an interstitial ad?
Because when I launch it I get this,
<Google> Cannot present interstitial. It is not ready.
Upvotes: 5
Views: 12637
Reputation: 5896
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
Upvotes: 23
Reputation: 74
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)
}
Upvotes: 0
Reputation: 1645
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)
}
}
Upvotes: 1
Reputation: 41
Swift 3.0
in viewDidLoad()
or createAndLoadInterstitial()
interstitial.delegate = self
then implement
func interstitialDidReceiveAd(_ ad: GADInterstitial) {
interstitial.present(fromRootViewController: self)
}
Upvotes: 4
Reputation: 2396
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
Upvotes: 1