我正在使用适用于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];
}
我想在类实现中禁用superview:
这是我到目前为止尝试循环遍历MainViewController
子视图的代码。
找到正确的子视图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);
}
}
答案 0 :(得分:4)
因为类实现实际上是一个插件,所以我可以使用以下代码:
for (UIView *subview in [self.viewController.view subviews]) {
if([subview isKindOfClass:[GADBannerView class]]) {
[subview removeFromSuperview];
}
}
根据Phonegap文档,每个插件都有self.viewController
属性。所以这只是循环并从超级视图中删除GADBannerView
的问题。
当然,我必须首先在插件类实现中#import "GADBannerView.h"
,因此它知道GADBannerView
。
答案 1 :(得分:3)
没有任何admob经验我会说禁用BannerView和任何控制器
如bannerView = nil
或[bannerView release]
还[bannerView removeFromSuperview]
或bannerView.hidden = YES
来自您自己的回答,以及您添加的代码,您需要做的只是
-(void)disableAds
{
// Turn the ads off.
[bannerView_ removeFromSuperview];
}
答案 2 :(得分:0)
试试这个:bannerView.rootViewController = nil;