2

我正在使用适用于 iOS 的 Google AdMob:

谷歌广告

我想知道我是否能够以编程方式关闭这些广告,以便它们停止显示。阅读 SDK 后,我看不到任何地方可以打开或关闭广告。

编辑:

这是我加载 Google AdMob 代码的方式:

主视图控制器.m

- (void) viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

    // Create a view of the standard size at the bottom of the screen.
    // Available AdSize constants are explained in GADAdSize.h.
    bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];
    // Must be a better way to position at bottom of page
    [bannerView_ setCenter:CGPointMake(kGADAdSizeBanner.size.width/2, 455)];
    // Specify the ad's "unit identifier." This is your AdMob Publisher ID.
    bannerView_.adUnitID = MY_BANNER_UNIT_ID;
    // Let the runtime know which UIViewController to restore after taking
    // the user wherever the ad goes and add it to the view hierarchy.
    bannerView_.rootViewController = self;
    [self.view addSubview:bannerView_];

    // Initiate a generic request to load it with an ad.
    GADRequest *request = [GADRequest request];
    // remove this line when you are ready to deploy for real
    request.testing = YES;
    [bannerView_ loadRequest:request];
}

我想在类实现中禁用超级视图:

这是迄今为止我尝试循环遍历MainViewController子视图的代码。

一旦我找到了正确的子视图GADBannerView,我希望能够将其删除。

其他类.m

- (void)disableAds
{
    // Turn the ads off.
    UIViewController *mainView = [[UIViewController alloc] initWithNibName:@"MainViewController" bundle:[NSBundle mainBundle]];
    for (UIView *subview in [mainView.view subviews]) {
        NSLog(@"View(s): %@", subview);
    }
}
4

3 回答 3

4

因为类实现实际上是一个插件,所以我能够使用以下代码:

for (UIView *subview in [self.viewController.view subviews]) {
    if([subview isKindOfClass:[GADBannerView class]]) {
        [subview removeFromSuperview];
    }
}

根据 Phonegap 文档,每个插件都有一个self.viewController属性。所以这只是一个循环并仅从超级视图中删除的问题GADBannerView

当然,我必须先#import "GADBannerView.h"在插件类实现中,这样它才能知道GADBannerView.

于 2012-09-07T12:15:23.270 回答
3

没有任何 admob 经验我会说只是禁用 BannerView 和任何控制器

喜欢bannerView = nil[bannerView release]

[bannerView removeFromSuperview]bannerView.hidden = YES


从您自己的答案和添加的代码中,您需要做的就是

 -(void)disableAds
{
    // Turn the ads off.
    [bannerView_ removeFromSuperview];
}
于 2012-09-07T06:58:26.890 回答
0

试试这个:bannerView.rootViewController = nil;

于 2015-10-30T08:47:12.217 回答