以编程方式关闭 Google AdMob 广告 (iOS)

fuz*_*uzz 2 ads objective-c admob ios

我正在使用 iOS 版 Google AdMob:

谷歌广告移动

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

编辑:

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

MainViewController.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];
}
Run Code Online (Sandbox Code Playgroud)

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

这是我迄今为止尝试循环子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);
    }
}
Run Code Online (Sandbox Code Playgroud)

fuz*_*uzz 5

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

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

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

当然,我必须#import "GADBannerView.h"首先在插件类实现中,以便它了解GADBannerView.