2014-07-24 33 views
-1

我可能是我,但我一直在努力争取2天的时间来让iAd框架与我正在开发的一个项目中的cocos2d一起工作。无法让iAd横幅与cocos2d一起工作

我有搜索谷歌,stackoverflow和cocos2d论坛,但没有运气。 我已经下载并尝试了很多来自stackoverflow站点和其他资源的示例。 当我把我的当前项目的代码结合起来,它不会工作。 不满意的结果差异很大,它可能会混淆他人,这就是为什么我还没有发布代码与此请求。无论如何,代码也可以在stackoverflow网站上找到,并且我已经加入了一些我已经尝试过的链接。 有一刻我非常接近解决方案,但是特定的迁移使AppDelegate方法搞砸了。 AppDelegate方法有2 @interface部分。我试图解决这个问题,但无法弄清楚如何解决它,并重新开始面对以前的备份问题。

谁可以帮助我在一些示例代码中将我推向正确的方向。

这里下面的一些东西/链接,我都准备好了尝试:

http://www.highoncoding.com/Articles/751_Implementing_iAd_on_Cocos2d_Application.aspx (太老)

How to add iad in cocos2d?

iOS 7 iAd cocos2d deprecated

iAd ADBannerView detect unloading

https://www.youtube.com/watch?v=fP2ijcXbCz4

在此先感谢

下面的代码是一个让我某种蓝色旗帜的底部侧关闭屏幕最接近。这不是我自己的,评论不是我的。

-(id) init 
{ 
    if((self=[super init])) { 
    UIViewController *controller = [[UIViewController alloc] init]; 
    controller.view.frame = CGRectMake(0, size.height -32, 320, 32); 

    ADBannerView *adView = [[ADBannerView alloc] initWithFrame:CGRectZero]; 

    adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifierLandscape]; 

    adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape; 
    [controller.view addSubview:adView]; 
    adView.delegate = self; 

    [[[CCDirector sharedDirector] view] addSubview:controller.view]; 
    [[[CCDirector sharedDirector] view] setNeedsLayout]; 
    } 
    [self layoutAnimated:YES]; 
} 

- (void)layoutAnimated:(BOOL)animated 
{ 
    // As of iOS 6.0, the banner will automatically resize itself based on its width. 
    // To support iOS 5.0 however, we continue to set the currentContentSizeIdentifier appropriately. 
    CGRect contentFrame = [CCDirector sharedDirector].view.bounds; 
    if (contentFrame.size.width < contentFrame.size.height) { 
     //_bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait; 
     [adView setAutoresizingMask:UIViewAutoresizingFlexibleWidth]; 
     } else { 
     _bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape; 
    } 

    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:^{ 
     _bannerView.frame = bannerFrame; 
    }]; 
} 

- (void)bannerViewDidLoadAd:(ADBannerView *)banner 
{ 
    if (!bannerIsVisible) 
    { 
     NSLog(@"bannerViewDidLoadAd"); 
     [UIView beginAnimations:@"animateAdBannerOn" context:NULL]; 
     banner.frame = CGRectOffset(banner.frame, 0, -32); //the offending line 

     self.position = ccpAdd(ccp(0, 32), self.position); 

     [UIView commitAnimations]; 
     bannerIsVisible = YES; 
    } 
} 

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error 
{ 
    if (bannerIsVisible) 
    { 
     NSLog(@"bannerView:didFailToReceiveAdWithError:"); 
     [UIView beginAnimations:@"animateAdBannerOff" context:NULL]; 
     banner.frame = CGRectOffset(banner.frame, 0, 32); //the other offending line 
     self.position = ccpAdd(ccp(0, -32), self.position); 

     [UIView commitAnimations]; 
     bannerIsVisible = NO; 
    } 
} 
+0

乔治,我明白了! 我在这里找到了解决方案, https://github.com/gururajios/Cocos2d-iAd 谢谢 –

回答

0

这是我的确。 如果您使用的是cocos2d v2,ios7并且您想要实施iAds,请使用下面的链接。 这将为您提供您正在寻找的解决方案。 使用MyiAd类检查HelloWorldLayer.h和.m文件,它非常容易(像往常一样)。

不要尝试其他任何东西,因为我已经为你做了。

https://github.com/gururajios/Cocos2d-iAd

希望此评论将帮助其他visiters找到一个解决方案的速度比我做到了!

Regards