arun
arun

Reputation: 1

iAd banner integration with cocos2d 1x banner does not show

I am trying to integrate iAd with my existing Cocosd2d 1.x project. I picked up the codes from this site. I put this in my main menu class. it compiles and link fine but the banner is not showing. The NSlog shows that bannerViewDidLoadAd is called. What am I missing here? Your help is highly appreciated. The code is given below.

//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

Upvotes: 0

Views: 94

Answers (2)

Francis Moy
Francis Moy

Reputation: 195

Regarding your specific question, I think @Liya is on the right track: you need to add the AdBannerView object to the view hierarchy; now, you're just creating the object but not using it.

Not sure if it will help, but I wrote recently a tutorial on integrating iAds with Cocos2d-x. The language is different (C++ instead of Objective-C), but the organization of code and some software engineering tips might be helpful if you want to integrate iAds with the scenes and layers of your game in Cocos2d: http://becomingindiedev.blogspot.com.es/2015/02/integrating-iad-in-cocos2d-x-v3x.html

Upvotes: 0

Liya
Liya

Reputation: 99

You add this code to your onEnter method,

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

Upvotes: 1

Related Questions