stephen D
stephen D

Reputation: 265

AdMob interstitial not showing What is wrong?

I am trying to add admob interstitial ads to my app but when I run my app no ad shows up. I just get a message in the logs saying :

<Google> To get test ads on this device, call: request.testDevices = @[ @« deviceID » ];

I'm pretty sure it knows im trying to show an add because of a previous error but it just won't appear.

here is my code( I added a print statement to the first part but it doesn't seem to take it into considiration ):

if interstitialad != nil {
            if interstitialad!.isReady {
                interstitialad?.present(fromRootViewController: self)

            }
        }

here is the second part of the code ( note both are in ViewDidLoad )

if interstitialad != nil {
            if interstitialad!.isReady {
                interstitialad?.present(fromRootViewController: self)
            }
        }


        func createAndLoadInterstitial() -> GADInterstitial {
            let request = GADRequest()
            let interstitial = GADInterstitial(adUnitID: "unit id")
            //request.testDevices = ["iPhone test device ID"]
            //request.testDevices = ["simulator ID"]
            interstitial.delegate = self
            interstitial.load(request)
            return interstitial
        }
        interstitialad = createAndLoadInterstitial()

What is wrong with this? Thanks !

Upvotes: 0

Views: 2804

Answers (3)

Google Ad Interstitial Objective C Working code:

- (void)startAdInterstial
{
 self.interstitial = [[GADInterstitial alloc] initWithAdUnitID:FIREBASE_ADMOBID];;
    GADRequest *request = [GADRequest request];
    request.testDevices = @[kGADSimulatorID,@"7b5e0f6aad46c15f1e9ef2e6d3d381b7"];
    
    _interstitial.delegate = self;
    [self.interstitial loadRequest:request];

}

#pragma mark -  interstitial delegate

- (void)interstitialDidReceiveAd:(GADInterstitial *)ad
{
    [_interstitial presentFromRootViewController:[APPDELEGATE window].rootViewController];
}

- (void)interstitial:(GADInterstitial *)ad didFailToReceiveAdWithError:(GADRequestError *)error
{
    NSLog(@"error during full screen view %@",error);
}


- (void)interstitialDidDismissScreen:(GADInterstitial *)interstitial {
    
}

Hope this will help you out in some other way.

Upvotes: 2

Daniel Storm
Daniel Storm

Reputation: 18898

You said you're trying to present your GADInterstitial in your viewDidLoad. This is not when you should be presenting your GADInterstitial. You need to give the GADInterstitial time to load the ad. Presenting an ad in your viewDidLoad is also against the AdMob TOS. You should be presenting the GADInterstitial during a transition/action in your application. You should also implement the GADInterstitial delegate methods so you know why the ad is failing to load, when it has actually loaded, and when the user has dismissed the ad so you can continue to transition them in your application.

Upvotes: 1

Here are some code which I used to initiate the AdMob in Objective-c:

AdMobHandler.m file:

//created 320x60 banner and displayed at the bottom of UIView.

//If your app in development stage then you need to add the device ID or simulator ID which will appear during AdMob Initiation. To get test ads on this device, call: request.testDevices = @[ @"xxxxxxxxxxxxxxxxxxxxxxxxxx" ];

- (void)initiateAndLoadAdMob:(UIViewController *)sender
{
GADRequest *request = [GADRequest request];

 GADBannerView  *bannerView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];

    request.testDevices = @[ @"xxxxxxxxxxxxxxxxxxxxxxxxxx <<Device ID>>",@"xxxxxxx<<Simulator ID>>" ];
    bannerView.adUnitID = FIREBASE_ADMOBID;
    bannerView.rootViewController = (id)self;
    bannerView.delegate = (id<GADBannerViewDelegate>)self;
    senderView = sender.view;
     bannerView.frame = CGRectMake(0, senderView.frame.size.height - bannerHeight, senderView.frame.size.width, bannerHeight);
    [senderView addSubview:bannerView];


}

If you able to understand and change code to Swift will gives you some idea and solve your above issue. Let me know if you have any queries for above code.

For more details check this below link:

https://firebase.google.com/docs/admob/ios/interstitial

Upvotes: 1

Related Questions