且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Admob 6.8.0:手动删除,隐藏或禁用横幅

更新时间:2023-12-05 09:35:22

如果有人遇到相同的问题,这就是我的解决方法.

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

问题在于我是"AdMob_Banner_On"方法上的行颠倒了.

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

尽管横幅显示得很完美,但它使bannerView_无法响应任何其他命令,因此,即使调用了AdMob_Banner_Off,也没有任何反应.

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:

开启:

 - (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.