与cocos2d 1x横幅的iAd横幅集成未显示

时间:2014-06-10 17:50:57

标签: ios cocos2d-iphone iad

我正在尝试将iAd与我现有的Cocosd2d 1.x项目集成。我从这个网站上获取了代码。我把它放在我的主菜单课上。它编译和链接很好,但横幅没有显示。 NSlog显示调用了bannerViewDidLoadAd。我在这里错过了什么?非常感谢您的帮助。代码如下。

//iAd begin

-(void)onEnter
{
   [super onEnter];

   NSLog(@"onEnter called");

   adView = [[ADBannerView alloc]initWithFrame:CGRectZero];
   adView.delegate = self;
   adView.requiredContentSizeIdentifiers = [NSSet   setWithObjects:ADBannerContentSizeIdentifier320x50, ADBannerContentSizeIdentifier480x32, nil];

   adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier480x32;
   CGSize widowSize = [[CCDirector sharedDirector] winSize];
   adView.center = CGPointMake(adView.frame.size.width/2, widowSize.height/2+145);
   adView.hidden = YES;

}

-(void)onExit
{
    NSLog(@"onExit called");
    adView.delegate = nil;
    [adView removeFromSuperview];
    [adView release];
    adView = nil;
    [super onExit];
}

-(void)bannerViewDidLoadAd:(ADBannerView *)banner
{
    NSLog(@"bannerViewDidLoadAd called");
    adView.hidden = NO;

}

-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
    NSLog(@"banner didFailToReceiveAdWithError called");
    adView.hidden = YES;
}

-(void)bannerViewActionDidFinish:(ADBannerView *)banner
{
    NSLog(@"bannViewActiondidFinishe called");
    [[UIApplication sharedApplication] setStatusBarOrientation:(UIInterfaceOrientation)[[CCDirector sharedDirector]deviceOrientation]];
}

-(BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave
{
    NSLog(@"bannerviewActionShouldBegin called");
    return YES;
}


//end iAd

2 个答案:

答案 0 :(得分:1)

您可以将此代码添加到onEnter方法

[[[CCDirector sharedDirector] view] addSubview:adView];

答案 1 :(得分:0)

关于您的具体问题,我认为@Liya是在正确的轨道上:您需要将AdBannerView对象添加到视图层次结构中;现在,您只是创建对象但不使用它。

不确定它是否会有所帮助,但我最近写了一篇关于将iAd与Cocos2d-x集成的教程。语言是不同的(C ++而不是Objective-C),但如果你想将iAd与Cocos2d中的场景和图层集成在一起,代码的组织和一些软件工程技巧可能会有所帮助:http://becomingindiedev.blogspot.com.es/2015/02/integrating-iad-in-cocos2d-x-v3x.html