【发布时间】: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。提前谢谢你。
我找到了解决方案
我在下面的链接中提供了答案
【问题讨论】:
-
请参考link.......
标签: iphone objective-c iad