【问题标题】:iOS 7 iAd cocos2d deprecatediOS 7 iAd cocos2d 已弃用
【发布时间】:2014-02-18 01:59:56
【问题描述】:

我正在尝试将 iAd 实现到我用 cocos2d 制作的 iOS 7 游戏中,我在 xcode 中添加了 iad 框架并进行了以下设置

在@implementation中我已经设置了

   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”,谁能帮我让它正常工作吗?我在网上查了一整天,没有任何代码可以工作。

提前致谢!

【问题讨论】:

    标签: objective-c ios7 cocos2d-iphone deprecated iad


    【解决方案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.

    【讨论】:

    • 我得到 'ADBannerContentSizeIdentifierPortrait' 已被弃用。还有'currentContentSizeIdentifier',你知道这些的ios 7替换代码吗?
    • 我在哪里使用 ADBannerContentSizeIdentifierPortrait ?删除 currentContentSizeIdentifier,并使用 setAutoresizingMask。
    • 非常感谢!工作就像一个魅力:) 感谢您花时间帮助我解决这个问题,过去几天我一直在努力解决这个问题,哈哈
    • 当我尝试在模拟器中运行下载的项目时出现错误,'Thread1: signal SIGABRT'说不能为nil
    • 正确,对不起,我应该这么说。如果我不指定屏幕宽度,它会在横向放置一个 320 像素的横幅。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-25
    • 2013-09-24
    • 1970-01-01
    相关资源
    最近更新 更多