编程关闭谷歌AdMob的广告(IOS) [英] Programmatically turn off Google AdMob Ads (iOS)
问题描述
我使用谷歌AdMob的iOS版:
我不知道我是否能够关闭这些广告以编程方式,使他们停止显示。通过SDK看完后,我看不到任何地方打开或关闭的广告。
编辑:
这是我如何加载谷歌AdMob的code:
MainViewController.m
- (无效)viewDidLoad中
{
[超级viewDidLoad中]
//装载从笔尖的观点后,是否有任何额外的设置。
//在屏幕的底部创建标准尺寸的景色。
//可用AdSize常量在GADAdSize.h解释。
bannerView_ = [[GADBannerView页头] initWithAdSize:kGADAdSizeBanner]。
//必须有更好的方式在页面底部定位
[bannerView_ setCenter:CGPointMake(kGADAdSizeBanner.size.width / 2,455)];
//指定广告的单位标识符。这是你的AdMob发布者ID。
bannerView_.adUnitID = MY_BANNER_UNIT_ID;
//让运行时知道的UIViewController服用后恢复
//用户无论广告的推移,并把它添加到视图层次结构。
bannerView_.rootViewController =自我;
[self.view addSubview:bannerView_]。
//初始化一个通用的请求与广告加载它。
GADRequest *请求= [GADRequest请求]
当您准备好部署真正//删除此行
request.testing = YES;
[bannerView_ loadRequest:申请];
}
我想在一个类实现禁用的SuperView:
这是在code我到目前为止已经通过了 MainViewController
子视图循环尝试。
一旦我找到了正确的子视图 GADBannerView
我希望能够将其删除。
OtherClass.m
- (无效)disableAds
{
//关闭广告关闭。
的UIViewController * MAINVIEW = [[UIViewController的页头] initWithNibName:@MainViewController捆绑:一个NSBundle mainBundle];
对于(的UIView *在[mainView.view子视图]子视图){
的NSLog(@视图(S):%@,子视图);
}
}
由于类的实现实际上是一个插件,我可以使用下面的code:
的(*的UIView子视图中的[self.viewController.view子视图]){
如果([子视图isKindOfClass:[GADBannerView类]){
[子视图removeFromSuperview];
}
}
据PhoneGap的文档,每个插件有一个 self.viewController
属性。因此,它是通过循环和消除的只是一个问题只有 GADBannerView
从上海华。
当然,我在插件类的实现必须#进口GADBannerView.h
第一所以知道关于 GADBannerView
。
I am using Google AdMob for iOS:
I was wondering whether I'm able to turn off these ads programmatically so they stop displaying. After reading through the SDK I can't see anywhere to toggle the ads on or off.
EDIT:
This is how I load the Google AdMob code:
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];
}
I'd like to disable the superview within a class implementation:
This is the code I've tried so far to loop through the MainViewController
subviews.
Once I've found the right subview GADBannerView
I want to be able to remove it.
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);
}
}
Because the class implementation was actually a plugin I was able to use the following code:
for (UIView *subview in [self.viewController.view subviews]) {
if([subview isKindOfClass:[GADBannerView class]]) {
[subview removeFromSuperview];
}
}
According to Phonegap documentation, every plugin has a self.viewController
property. So it was just a matter of looping through and removing only the GADBannerView
from the superview.
Of course I had to #import "GADBannerView.h"
in the plugin class implementation first so it knew about GADBannerView
.
这篇关于编程关闭谷歌AdMob的广告(IOS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!