gpt4 book ai didi

iphone - 如何在模拟器中显示测试 IAd 横幅

转载 作者:搜寻专家 更新时间:2023-10-30 20:01:19 25 4
gpt4 key购买 nike

大家好,我导入了 iAd 框架并为 iAd 实现了代码。我的示例代码如下所示

.h文件

#import <UIKit/UIKit.h>
#import <iAd/iAd.h>

@interface IadTestViewController : UIViewController<ADBannerViewDelegate> {
BOOL isBannerVisible;
IBOutlet ADBannerView *banner;

}
@property(nonatomic,assign)BOOL isBannerVisible;
@property(nonatomic,retain)IBOutlet ADBannerView *banner;

@end

.m 文件我实现了委托(delegate)方法

 #import "IadTestViewController.h"

@implementation IadTestViewController
@synthesize banner,isBannerVisible;


- (void)viewDidLoad {
[super viewDidLoad];
isBannerVisible=NO;
bannerView=[[ADBannerView alloc]initWithFrame:CGRectZero];
bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
bannerView.delegate=self;
[self.view addSubview:bannerView];

- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
if (!self.isBannerVisible)
{
[UIView beginAnimations:@"animateAdBannerOn" context:NULL];
// Assumes the banner view is just off the bottom of the screen.
bannerView.frame = CGRectOffset(bannerView.frame, 0, -bannerView.frame.size.height);
[UIView commitAnimations];
self.isBannerVisible = YES;
}

  - (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
NSLog(@"the failed error is %@",error);
if (self.isBannerVisible)
{
[UIView beginAnimations:@"animateAdBannerOff" context:NULL];
// Assumes the banner view is placed at the bottom of the screen.
bannerView.frame = CGRectOffset(bannerView.frame, 0, bannerView.frame.size.height);
[UIView commitAnimations];
self.isBannerVisible = NO;
}

我的 xib 连接格式正确。我仍然没有在我的模拟器中收到 IAd 横幅,我的日志语句给我这样的错误

Error Domain=ADErrorDomain Code=5 “操作无法完成。横幅 View 可见但没有内容” UserInfo=0x574fdd0 {ADInternalErrorCode=5, NSLocalizedFailureReason=横幅 View 可见但没有内容内容

我知道当广告为零时 iAd 横幅不可见。但我正在尝试显示测试广告,即使这对我的程序来说也是不可能的。我不知道我犯了什么错误或我忘记了执行哪一步。我看到了很多我们的 stackoverflow.com 中有类似的问题,但没有一个答案可以解决我的问题。任何人都可以帮助我解决这个问题,请提供一些示例代码以在模拟器中显示 TestAdd。提前致谢。

我找到了解决方案

我在下面的链接中提供了答案

Why does test iAd for barebones project not display?

最佳答案

第一步:

1.import iAd Framework to the Application.

2.Provide #import in the particular controller where you want to show your Add.

3.Provide it’s delegate UIViewController

4.Provide one view to that particular ViewController.Assume I have taken

@property (weak, nonatomic) IBOutlet UIView *contentView;

第 2 步:

在ViewDidLoad方法中分配

- (void)viewDidLoad
{
_bannerView = [[ADBannerView alloc] init];
_bannerView.delegate = self;

[super viewDidLoad];
[self.view addSubview:_bannerView];
}

第 3 步:

提供我在下面提到的委托(delegate)方法。

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
_bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
} else {
_bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
}
[self layoutAnimated:duration > 0.0];
}

- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
[self layoutAnimated:YES];
}

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
[self layoutAnimated:YES];
}

- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave
{

return YES;
}

- (void)bannerViewActionDidFinish:(ADBannerView *)banner
{

}
- (void)layoutAnimated:(BOOL)animated
{
if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) {
_bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
} else {
_bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
}

CGRect contentFrame = self.view.bounds;
CGRect bannerFrame = _bannerView.frame;
if (_bannerView.bannerLoaded) {
contentFrame.size.height -= _bannerView.frame.size.height;
bannerFrame.origin.y = contentFrame.size.height;
} else {
bannerFrame.origin.y = contentFrame.size.height;
}

[UIView animateWithDuration:animated ? 0.25 : 0.0 animations:^{
self.contentView.frame = contentFrame;
[self.contentView layoutIfNeeded];
_bannerView.frame = bannerFrame;
}];
}

更多详情请引用此link

关于iphone - 如何在模拟器中显示测试 IAd 横幅,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5947552/

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