【问题标题】:how to display test IAd banner in the simulator如何在模拟器中显示测试 IAd 横幅
【发布时间】:2011-05-10 08:50:30
【问题描述】:

大家好,我导入了 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 文件我实现了委托方法

 #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 "The operation couldn’t be completed. Banner view is visible but does not have content" UserInfo=0x574fdd0 {ADInternalErrorCode=5, NSLocalizedFailureReason=Banner view is visible but does not have content}

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

我找到了解决方案

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

Why does test iAd for barebones project not display?

【问题讨论】:

标签: iphone objective-c iad


【解决方案1】:

第 1 步:

1.将 iAd 框架导入应用程序。

2.在要显示添加的特定控制器中提供#import。

3.提供它的委托 UIViewController

4.为那个特定的 ViewController 提供一个视图。假设我已经采取了

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

第 2 步:

在 ViewDidLoad 方法中分配

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

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

第 3 步:

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

- (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

【讨论】:

  • 一个疑问,我们是否应该将 contentView 连接到 xib 中的视图控制器视图,它似乎不起作用,我尝试不连接和连接。另外我们是否应该采取另一个视图和我们想要的位置在 xib 中并将内容视图连接到该视图。我什至尝试过,它不起作用。请澄清一下,我无法在模拟器中显示广告 :)
【解决方案2】:

看起来这是 Apple 服务器端的问题。确保您的配置文件是最新的,并确保您的应用已注册以接收广告(通过 iTunes 连接)。我看不出你的代码有什么问题。

查看此link 了解更多信息。

【讨论】:

  • Rob 非常感谢您的回答,我在最后一分钟得到了解决方案。
【解决方案3】:

首先,您必须检查您的横幅框架是否正确...如果正确,那么如果您在办公室工作,您可能应该检查系统中的代理设置...您可能需要拥有从互联网下载内容的下载权限。这可能只是一个问题,因为您已经说过您正在正确地做其他所有事情...

还有一件事 AAAAAA.... 我认为您必须首先通过 iTunes connect 注册苹果的 iAd 网络才能接收来自他们的任何广告....我建议您查看他们在 iAd 上的文档以获得更清晰...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-09
    • 1970-01-01
    相关资源
    最近更新 更多