为什么 AdWhirl 在获取正常时不显示广告?



按照Ray Wenderlich教程,我合并了最新的AdWhirl文件夹,删除了我不使用的适配器,使用iAd设置了一个帐户,上传了一些房屋横幅,配置了AdWhirl交付,并在我的Cocos2d应用程序中实现了检索/显示代码。 我的日志显示广告已成功检索,但它们没有显示在屏幕上。 我在想它们要么显示在屏幕外(无人区),要么隐藏在 CCLayer 后面。 非常感谢有关如何测试/解决此问题的任何建议。 如果有帮助,这是一个只有景观方向。

更新:RW 教程对于 Cocos2d 版本 2.0 用户已过时...解决方案见下文

这是我的AdWhirl代码:

图书馆.h

#import "AdWhirlView.h"
#import "AdWhirlDelegateProtocol.h"
#import "RootViewController.h"
@interface Library : CCLayer <AdWhirlDelegate>{

这是教程所说的,但已经过时

//RootViewController *viewController;

这是需要的

UINavigationController *viewController
AdWhirlView *adWhirlView;
enum GameStatePP _state; }
@property(nonatomic,retain) AdWhirlView *adWhirlView; 
@property(nonatomic) enum GameStatePP state;

Library.mm

@implementation Library
@synthesize state = _state, adWhirlView;

在初始化中

self.state = kGameStatePlaying;

然后是AdWhirl方法

- (void)adWhirlWillPresentFullScreenModal {
if (self.state == kGameStatePlaying) {
[[CCDirector sharedDirector] pause];} }
- (void)adWhirlDidDismissFullScreenModal {
if (self.state == kGameStatePaused)
    return;
else {
    self.state = kGameStatePlaying;
    [[CCDirector sharedDirector] resume]; }}
- (NSString *)adWhirlApplicationKey {
return @"myadWhirlKeyGoesHere"; }
- (UIViewController *)viewControllerForPresentingModalView {
return viewController;}
-(void)adjustAdSize {
[UIView beginAnimations:@"AdResize" context:nil];
[UIView setAnimationDuration:0.2];
CGSize adSize = [adWhirlView actualAdSize];
CGRect newFrame = adWhirlView.frame;
newFrame.size.height = adSize.height;
CGSize winSize = [CCDirector sharedDirector].winSize;
    newFrame.size.width = winSize.width;
newFrame.origin.x = (self.adWhirlView.bounds.size.width - adSize.width)/2;
    newFrame.origin.y = (winSize.height - adSize.height);
adWhirlView.frame = newFrame;
[UIView commitAnimations]; }
- (void)adWhirlDidReceiveAd:(AdWhirlView *)adWhirlVieww {
[adWhirlView rotateToOrientation:UIInterfaceOrientationLandscapeRight];
[self adjustAdSize];
NSLog(@"Library - adWhirlDidReceiveAd");
NSLog(@"%@",[adWhirlView mostRecentNetworkName]); }
-(void)adWhirlDidFailToReceiveAd:(AdWhirlView *)adWhirlVieww usingBackup:(BOOL)yesOrNo {
NSLog(@"Library - adWhirlDidFailToReceiveAd");
NSLog(@"%@",[adWhirlView mostRecentNetworkName]); }
-(void)onEnter {

这是教程所说的,对于Cocos2d 2.0版本用户来说是错误的

//viewController = [(AppDelegate *)[[UIApplication sharedApplication] delegate] viewController];

这是正确的方法

viewController = [(AppDelegate *)[[UIApplication sharedApplication] delegate] navController];
self.adWhirlView = [AdWhirlView requestAdWhirlViewWithDelegate:self];
self.adWhirlView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin;
[adWhirlView updateAdWhirlConfig];
CGSize adSize = [adWhirlView actualAdSize];
CGSize winSize = [CCDirector sharedDirector].winSize;
self.adWhirlView.frame = CGRectMake((winSize.width/2)-(adSize.width/2),winSize.height-adSize.height,winSize.width,adSize.height);
self.adWhirlView.clipsToBounds = YES;
[viewController.view addSubview:adWhirlView];
[viewController.view bringSubviewToFront:adWhirlView];
[super onEnter]; }
-(void)onExit {
if (adWhirlView) {
    [adWhirlView removeFromSuperview];
    [adWhirlView replaceBannerViewWith:nil];
    [adWhirlView ignoreNewAdRequests];
    [adWhirlView setDelegate:nil];
    self.adWhirlView = nil;
}
[super onExit]; }
- (void) dealloc {
self.adWhirlView.delegate = nil;
self.adWhirlView = nil; }

在我的应用程序代表中。

错:

//RootViewController *viewController; 
//UIViewController *viewController;

这是正确的,并且在 2.0 Cocos2d 模板中提供,因此不需要添加,只需要使用:

UINavigationController *navController_;

所以这些是不需要的

//@property (nonatomic, retain) RootViewController *viewController;
//@property (nonatomic, retain) UIViewController *viewController;

AppDelegate.mm

@synthesize window=window_, navController=navController_, director=director_; 

不需要,因为我们将使用导航控制器:

//viewController = viewController_;

DidFinishLaunchingWithOptions(所有对viewController的引用都被注释掉了)

//viewController = [[UIViewController alloc] initWithNibName:nil bundle:nil];
//viewController.wantsFullScreenLayout = YES;
CCGLView *glView = [CCGLView viewWithFrame:[window_ bounds]
    pixelFormat:kEAGLColorFormatRGB565
            depthFormat:0
            preserveBackbuffer:NO
            sharegroup:nil   
            multiSampling:NO 
            numberOfSamples:0];
director_ = (CCDirectorIOS*) [CCDirector sharedDirector];
director_.wantsFullScreenLayout = YES;
[director_ setDisplayStats:NO];
[director_ setAnimationInterval:1.0/60];
[director_ setDelegate:self];
[director_ setProjection:kCCDirectorProjection2D];
[director_ setView:glView];
if( ! [director_ enableRetinaDisplay:YES] )CCLOG(@"Retina Display Not supported");
navController_ = [[UINavigationController alloc] initWithRootViewController:director_];
navController_.navigationBarHidden = YES;

这是重要的一行,设置导航控制器

[window_ addSubview:navController_.view];
[glView setMultipleTouchEnabled:YES];
//[viewController_ setView:glView];
//[window_ addSubview:viewController_.view];
[window_ makeKeyAndVisible];
[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];
[CCFileUtils setiPadSuffix:@"-ipad"];
[CCFileUtils setRetinaDisplaySuffix:@"-hd"];
[CCTexture2D PVRImagesHavePremultipliedAlpha:YES];
[director_ pushScene: [TitleScene scene]]; 
return YES;

使用以下行指定视图控制器:

viewController = [(AppDelegate *)[[UIApplication sharedApplication] delegate] viewController];

是否确定您的应用委托正在设置其视图控制器属性?换句话说,viewController是零吗?我会检查一下。

如果仍然遇到此问题,请使用下面的代码。

你以前的是

[viewController.view addSubview:adWhirlView];<br>
[viewController.view bringSubviewToFront:adWhirlView];

我的建议是

[[CCDirector sharedDirector].view addSubview:adWhirlView];<br>
[[CCDirector sharedDirector].view bringSubviewToFront:adWhirlView];

也许,在那之后你可以看到广告。

最新更新