gpt4 book ai didi

ios - 隐藏广告横幅导致不再请求/显示广告

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

我有一个使用 AdMob 中介服务的测试应用程序设置,目前仅在测试设备上使用。我已经根据文档设置了所有必需的方法。我遇到一个问题,当发生“无法接收广告”错误时,不再请求或显示广告?

标题:

#import <UIKit/UIKit.h>
#import "GADBannerViewDelegate.h"

@class GADBannerView, GADRequest;

@interface AdTestViewController : UIViewController
<GADBannerViewDelegate> {
GADBannerView *bannerView_;
}

@property (nonatomic, retain) GADBannerView *bannerView;

- (GADRequest *)createRequest;

@end

导入文件

#import "AdTestViewController.h"
#import "Constants.h"
#import "GADBannerView.h"
#import "GADRequest.h"

@implementation AdTestViewController

@synthesize bannerView = bannerView_;

- (void)viewDidLoad {
[super viewDidLoad];

// Create a view of the standard size at the top of the screen.
// Available AdSize constants are explained in GADAdSize.h.
//bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];
// Initialize the banner at the bottom of the screen.
//CGPoint origin = CGPointMake(0.0,
// self.view.frame.size.height -
// CGSizeFromGADAdSize(kGADAdSizeBanner).height);
self.bannerView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];
//origin:origin];

self.bannerView.adUnitID = kAdMobPublisherID;
self.bannerView.delegate = self;
[self.bannerView setRootViewController:self];
[self.view addSubview:self.bannerView];
self.bannerView.center =
CGPointMake(self.view.center.x, self.bannerView.center.y);
[bannerView_ loadRequest:[self createRequest]];

bannerView_.backgroundColor = [UIColor blueColor];


// Make the request for a test ad. Put in an identifier for
// the simulator as well as any devices you want to receive test ads.
GADRequest *request = [GADRequest request];
request.testDevices = [NSArray arrayWithObjects:
@"4D047EB9-A3A7-441E-989E-C5437F05DB04",
@"YOUR_DEVICE_IDENTIFIER",
nil];

}

- (GADRequest *)createRequest {
GADRequest *request = [GADRequest request];

// Make the request for a test ad. Put in an identifier for the simulator as
// well as any devices you want to receive test ads.
request.testDevices = [NSArray arrayWithObjects:
@"4D047EB9-A3A7-441E-989E-C5437F05DB04",
@"YOUR_DEVICE_IDENTIFIER",
nil];
return request;
}

- (void)adView:(GADBannerView *)view didFailToReceiveAdWithError:(GADRequestError *)error;
{
NSLog(@"Error - did Fail to Receive an Ad");
bannerView_.hidden = YES;

}

- (void)adViewDidReceiveAd:(GADBannerView *)view;
{
NSLog(@"Ad Received");
bannerView_.hidden = NO;
}

@end

我在我的日志中看到的是几次“已收到广告”,然后是“错误 - 未能收到广告”...此日志之后没有更多条目,就像它停止请求一样?目前仅在模拟器上进行测试。

关于如何解决此问题的任何想法,或者在收到错误/未收到广告时隐藏 View 的潜在替代方法?

最佳答案

我发现了同样的事情——当 GADBannerView 被隐藏时,不再发送请求。

我成功尝试的一件事是将 GADBannerView 移到屏幕外而不是隐藏它。当然,您只想在 didFailToReceiveAdWithError 时执行此操作,然后在 adViewDidReceiveAd 时将其移回屏幕。我让这个工作正常,因此当广告来来去去时,用户会看到一个漂亮的动画,就像 iAd 所鼓励的那样。

简而言之,下面的代码会将您的 GADBannerView(此处称为 mAdBannerView)放置在屏幕底部或屏幕外,具体取决于 bool 值 adIsLoaded

  CGRect bannerFrame = mAdBannerView.frame;
bannerFrame.origin.y = self.view.bounds.size.height - (adIsLoaded * bannerFrame.size.height);
mAdBannerView.frame = bannerFrame;

关于ios - 隐藏广告横幅导致不再请求/显示广告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14529865/

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