gpt4 book ai didi

ios - 如何在 Objective c 中隐藏谷歌广告

转载 作者:行者123 更新时间:2023-11-28 21:43:39 24 4
gpt4 key购买 nike

在我的项目中,我实现了 Google-Mobile-Ads SDK。我已经按照谷歌网站上写的所有步骤进行操作。我可以在我的所有 View Controller 中访问谷歌广告,因为我已经在我的 AppDelegate 中对其进行了编码。

现在,我想让它从第一个 View Controller 中隐藏它(就像我们可以隐藏导航栏一样),如何实现它?

在 AppDelegate 的 DidFinishLaunchingMethod 中为谷歌广告编码:-

 bannerView=[[GADBannerView alloc] initWithFrame:CGRectMake(0, self.window.frame.size.height-50, self.window.frame.size.width, 50)];
[self.window addSubview:bannerView];

bannerView.adUnitID = @"ca-app-pub-8809802355107737/4999307809";
bannerView.rootViewController = self.window.rootViewController;
bannerView.delegate=self;
GADRequest *request = [GADRequest request];
request.testDevices = @[ @"eba07768136b615eee7c1f8acde25c1b",kGADSimulatorID ];
[bannerView loadRequest:request];

[self.window makeKeyAndVisible];

return YES;

我在 appDelegate 类中也有这个方法:-

 - (void)adViewDidReceiveAd:(GADBannerView *)view;
{
if (container.view.frame.size.height==self.window.frame.size.height-50) {

}
else
{
CGRect navFrame = container.view.frame;
navFrame.size.height -= 50;
container.view.frame = navFrame;
}
NSLog(@"asdhaskda");
}

最佳答案

在 firstViewController 中:

-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] postNotificationName:@"HIDEBANNER" object:nil];
}

-(void)viewDidDisappear:(BOOL)animated{
[super viewDidDisappear:animated];
[[NSNotificationCenter defaultCenter] postNotificationName:@"SHOWBANNER" object:nil];
}

在 AppDelegate.m 文件中,在 didFinishLaunchingWithOptions 中:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(hideBanner) name:@"HIDEBANNER" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showBanner) name:@"SHOWBANNER" object:nil];

同时实现这两个功能。我不确定这些功能中到底必须包含什么。也许是这样的:

 -(void)showBanner{
[bannerView setHidden:NO];
//this is from your code
if (container.view.frame.size.height==self.window.frame.size.height-50) {

}
else
{
CGRect navFrame = container.view.frame;
navFrame.size.height -= 50;
container.view.frame = navFrame;
}
}

-(void)hideBanner{
[bannerView setHidden:YES];
CGRect navFrame = container.view.frame;
navFrame.size.height = self.window.frame.size.height;
container.view.frame = navFrame;
}

关于ios - 如何在 Objective c 中隐藏谷歌广告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31137734/

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