iOS 7 iAd cocos2d deprecated(iOS 7 iAd cocos2d 已弃用)
问题描述
我试图将 iAd 实现到我用 cocos2d 制作的 iOS 7 游戏中,我在 xcode 中添加了 iad 框架并进行了以下设置
Im trying to get iAd implemented to a iOS 7 game I made with cocos2d, I added iad framework in xcode and have the setup below
在@implementation中我已经设置了
in @implementation I have set
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",谁能帮我让它正常工作吗?我在网上查了一整天,没有任何代码可以工作.
I get an error about '_adview' and as well as 'currentContentSizeIdentifier' deprecated, can anyone help me get this working correctly? Ive checked online all day and couldnt get any of the code working.
提前致谢!
推荐答案
试试这个新代码:
- (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];
}
这里是 Cocos2d 3.0 的新 iAd 代码.
这篇关于iOS 7 iAd cocos2d 已弃用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:iOS 7 iAd cocos2d 已弃用
基础教程推荐
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01