gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:09:17 25 4
gpt4 key购买 nike

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

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];
}

我想在类实现中禁用 super View :

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

找到正确的 subview GADBannerView 后,我希望能够将其删除。

OtherClass.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);
}
}

最佳答案

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

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

根据 Phonegap 文档,每个插件都有一个 self.viewController 属性。因此,这只是循环遍历并仅从 super View 中删除 GADBannerView 的问题。

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

关于objective-c - 以编程方式关闭 Google AdMob 广告 (iOS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12313219/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com