문제

There are tons of similar questions here, but none of the solutions are working on the latest AdMob SDK. At least I couldn't make it work.

Loading:

- (void)AdMob_Banner_On
 {
    bannerView_.adUnitID = kAdMobID;
    bannerView_.rootViewController = self;
    [bannerView_ loadRequest:[GADRequest request]];
    (...)
}

They are running perfectly, and now removing... all solutions I found are quite simple, but they don't work:

 - (void)AdMob_Banner_Off {

     NSLog(@"Admob: Turning Off");

     bannerView_.hidden = YES;
     [bannerView_ removeFromSuperview];
     [bannerView_ setDelegate:nil];
     bannerView_ = nil;
 }

Some times I need all screen available, I can't show ads all the time. Any ideas?

도움이 되었습니까?

해결책

In case anyone has the same problem, here is how I fix it.

The problem was that I was that the lines on the "AdMob_Banner_On" method were inverted.

Although the banner was showing up perfectly, it made the bannerView_ unable to respond to any other command, so even if the AdMob_Banner_Off was called, nothing was happening.

Now the code that works. The first thing you should do it to set the position of the banner, and then calling it. That was my problem. This code should work fine:

Turning on:

 - (void)AdMob_Banner_On {

     NSLog(@"Admob: Turning On");

     // Making it on the bottom:

     CGPoint origin = CGPointMake(0.0,self.view.frame.size.height - CGSizeFromGADAdSize(kGADAdSizeSmartBannerPortrait).height);
          bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerPortrait origin:origin];

     bannerView_.adUnitID = kAdMobID;
     bannerView_.rootViewController = self;
     bannerView_.delegate = self;
     [self.view addSubview:bannerView_];
     [bannerView_ loadRequest:[GADRequest request]];

 }


 - (void)AdMob_Banner_Off: {

     NSLog(@"Admob: Turning Off");

     [bannerView_ removeFromSuperview];

 }

With this code you can turn on and off the banner as you want. This is useful to apps that can't show the banner all the time.

다른 팁

initAd must be in viewDidLoad I solved by it.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top