2014-02-18 42 views
2

我试着让iAd的实现到iOS的7场比赛我用cocos2d的制作,我说在Xcode IAD框架,并在@implementation下面的iOS 7的iAd的cocos2d弃用

设置我已经设置

ADBannerView *_bannerView; 

然后

-(id)init 
{ 
    if((self= [super init])) 
    { 
     // On iOS 6 ADBannerView introduces a new initializer, use it when available. 
     if ([ADBannerView instancesRespondToSelector:@selector(initWithAdType:)]) { 
      ADBannerView *_adView = [[ADBannerView alloc] initWithAdType:ADAdTypeBanner]; 

     } else { 
      _adView = [[ADBannerView alloc] init]; 
     } 
     _adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifierPortrait]; 
     _adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait; 
     [[[CCDirector sharedDirector]view]addSubview:_adView]; 
     [_adView setBackgroundColor:[UIColor clearColor]]; 
     [[[CCDirector sharedDirector]view]addSubview:_adView]; 
     _adView.delegate = self; 
    } 
    [self layoutAnimated:YES]; 
    return self; 
} 


- (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 { 
    [self layoutAnimated:YES]; 
} 

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error { 
    [self layoutAnimated:YES]; 
} 

我得到“_adview”和以及“currentContentSizeIdentifier”不赞成使用,任何人都可以帮助我得到一个错误,这正常工作?我整天在线检查,无法得到任何代码工作。

在此先感谢!

回答

1

试试这个新代码:

- (void)createAdBannerView 
{ 
    _adBannerView = [[ADBannerView alloc] initWithFrame:CGRectZero]; 
    _adBannerView.delegate = self; 
    [_adBannerView setAutoresizingMask:UIViewAutoresizingFlexibleWidth]; 

    CGRect frame = _adBannerView.frame; 
    frame.origin.y = -frame.size.height; 
    frame.origin.x = 0.0f; 

    _adBannerView.frame = frame; 

    AppDelegate * app = (((AppDelegate*) [UIApplication sharedApplication].delegate)); 
    [app.navController.view addSubview:_adBannerView]; 
} 

Here new iAd Code for Cocos2d 3.0.

enter image description here

+0

我得到 'ADBannerContentSizeIdentifierPortrait' 已经过时了。以及'currentContentSizeIdentifier',你知道那些ios 7替换代码吗? –

+0

我在哪里使用了ADBannerContentSizeIdentifierPortrait?删除currentContentSizeIdentifier,并使用setAutoresizingMask。 – Guru

+1

非常感谢!工作就像一个魅力:)感谢您抽出时间来帮助我,这一点,我一直在努力与这几天lol –