2011-05-10 120 views
3

喜所有显示试验IAD横幅我进口iAd的帧的工作和用于iAd.My样本代码如下所示如何在模拟器

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

}

我的厦门国际银行连接的连接以及formated.still我不是我的模拟器获得的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横幅在广告为零时不可见,但我试图展示测试广告,即使这也不可能与我的程序。我不知道我犯了什么错误或我忘了执行哪一步ent.I在我们的stackoverflow.com中看到了许多类似的问题,但没有一个答案纠正我的问题。任何人都可以帮助我解决这个问题,并提供一些示例代码来显示模拟器中的TestAdd。敬请期待。

我得到了解决

我在下面的链接

Why does test iAd for barebones project not display?

+0

请参考此[链接](http://www.raywenderlich.com/1371/how-to-integrate-iad-into-your-iphone-应用程序).​​............. – Nirav 2011-06-08 09:35:38

+0

[iAd错误“广告库存不可用”]的可能重复(http://stackoverflow.com/questions/3720459/iad-error-ad-inventory-不可用) – 2013-08-27 23:52:19

回答

1

首先必须检查所提供的答案,如果横幅的帧正确与否....如果多数民众赞成给予对,如果你在办公室工作,你应该检查你的系统中的代理设置...你可能需要有下载权利,从互联网上下载内容..这可能只是一个问题,因为你已经说你正在做每一件事情lse正确...

还有一件事AAAAAA ....我认为你必须先通过iTunes连接注册到苹果的iAd网络,以接收他们的任何广告....我建议你检查他们的文件在iAd的更清晰......

2

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

查看此link了解更多。

+0

Rob非常感谢您的回答,我在最后一个nit中得到了解决方案。 – ajay 2011-05-13 05:43:40

+0

没问题。不要害羞投票或接受答案=) – Rob 2011-05-13 07:12:30

3

步骤1:

1,引进的iAd框架到应用程序。

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

3.提供它的委托的UIViewController

4,提供一个以特定视图控制器。假设我已

@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

+0

有一个疑问,我们是否应该将contentView连接到我们在xib中的视图控制器视图中,它似乎不起作用,我尝试了没有连接和连接。我们也应该采取另一种观点,我们希望在xib中的位置,并将内容视图连接到该视图。我甚至尝试过,它没有工作。请澄清一下,我无法在模拟器中显示广告:) – 2014-03-24 13:20:52