iphone iAd 加入方法 以及注意事项

分类:IOS    发布时间:2011/3/12 17:02:00

注意必须再4.0上才能看到广告  广告设置再 iTunes 里 将广告打开 即可
.h
#import <iAd/iAd.h>
@interface iAdsDemoViewController : UIViewController
<ADBannerViewDelegate> {
    ADBannerView *adView;
}
.m
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    //竖屏
    adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
    adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier320x50;
    [self.view addSubview:adView];
    adView.delegate = self;
    adView.hidden = YES;
    //横屏
    //ADBannerView *adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
//    adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifier480x32];
//    adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier480x32;
//    [self.view addSubview:adView];
    adView.requiredContentSizeIdentifiers = [NSSet setWithObjects: ADBannerContentSizeIdentifier320x50, ADBannerContentSizeIdentifier480x32, nil];
    [super viewDidLoad];
}
- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave
{
    NSLog(@"should begin");
    return YES;
}
- (void)bannerViewActionDidFinish:(ADBannerView *)banner
{
    NSLog(@"did finish");
}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
    NSLog(@"%d",adView.bannerLoaded);
    adView.hidden = NO;
    NSLog(@"did load");
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
    NSLog(@"error:%@",error);
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    NSLog(@"rotate");
    //adView.frame = CGRectZero;
    if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation))
    {
        adView.currentContentSizeIdentifier =
        ADBannerContentSizeIdentifier480x32;
        adView.frame = CGRectZero;
    }
    else
    {
        adView.currentContentSizeIdentifier =
        ADBannerContentSizeIdentifier320x50;
        adView.frame = CGRectZero;
    }   
}
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return YES;

 

  相信很多开发者在自己的应用里加入 iAd 后,都遇到了不能通过苹果审核的问题。CocoaChina 版主“lvyile”为您总结了让加了 iAd 的应用通过审核的注意事项:

  不能取得广告的时候,一定要隐藏 iAd 广告 Banner。要设置Delegate,出错的话立刻把 Banner 隐掉。而且要一开始就把BannerView的属性设置为hidden = YES;直到请求到广告才显示出现。

  另外有的时候会出现这样的 log:
error:Error Domain=ADErrorDomain Code=0 "no qualified ads found for this request" UserInfo=0x1bcff0 {NSLocalizedDescription=no qualified ads found for this request}
2010-07-18 22:54:49.897 iAdDemo_AppStoreSafe[2514:307] error:Error Domain=ADErrorDomain Code=0 "no qualified ads found for this request" UserInfo=0x127490 {NSLocalizedDescription=no qualified ads found for this request}

  别着急,等着就好,广告会出现的

最新评论

我要发表评论

名称:
电子邮件:
个人主页:
内容:

 博客分类