如何在模拟器中显示测试IAd横幅 [英] how to display test IAd banner in the simulator

查看:158
本文介绍了如何在模拟器中显示测试IAd横幅的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好我导入iAd帧工作并实现了iAd.My示例代码的代码如下所示

hi all i imported iAd frame work and implemented code for the iAd.My sample code is below shown

.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文件我实现了委托方法

.m file i implemented delegate methods

 #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横幅,我的日志声明给我这样的错误

And my xib connections are connected well formated.still i am not getting IAd banner in my simulator and my Log statement giving me error like this

错误Domain = ADErrorDomain Code = 5操作无法完成。横幅视图可见,但没有内容UserInfo = 0x574fdd0 {ADInternalErrorCode = 5,NSLocalizedFailureReason =横幅视图可见,但没有内容}

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

I know iAd banner not visible when ads are zero.But i am trying to display test advertisement even that also not possible to with my program.I dont know what mistake i made or which step i forget to implement.I seen many similar questions in our stackoverflow.com but none of the answers rectify my problem.Can any one help me out from this and please provide some sample code to show the TestAdd in the simulator .Thank you in advance.

我得到了解决方案

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

i provided answer in the below link

为什么测试iAd for barebones项目不显示?

推荐答案

步骤1:


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

1.import iAd Framework to the Application.

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

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

3.提供它的委托UIViewController

3.Provide it’s delegate UIViewController

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

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



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

第2步:

分配给它ViewDidLoad方法

Allocate it in ViewDidLoad method

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

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

第3步:

提供它所提到的委托方法。

Provides it’s delegate methods which i have mention bellowed.

- (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;
}];
}

更多细节请参考链接

这篇关于如何在模拟器中显示测试IAd横幅的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆