2012-07-30 68 views
0

我刚刚使用iAds和adMob将adWhirl实现到了我的应用程序。一切正常编译和adMob工作完美,但我的iAd的大小不正确。该广告看起来像是正确的大小,但它实际上似乎被切断了。大约1/4的广告看起来像缺少了。由于我没有错误,我不知道在哪里寻找解决这个问题。iAds槽adWhirl没有完全加载

这里是我的广告栏外观的屏幕截图。

http://imgur.com/waPPD

在正确的方向任何帮助或只是微调,将不胜感激!

这里是AdWhirlAdapteriAd.h

#import "AdWhirlAdNetworkAdapter.h" 
#import <iAd/ADBannerView.h> 

@interface AdWhirlAdapterIAd : AdWhirlAdNetworkAdapter <ADBannerViewDelegate> { 
    NSString *kADBannerContentSizeIdentifierPortrait; 
    NSString *kADBannerContentSizeIdentifierLandscape; 
} 

+ (AdWhirlAdNetworkType)networkType; 

@end 

这里是AdWhirlAdapteriAd.m

#import "AdWhirlAdapterIAd.h" 
#import "AdWhirlAdNetworkConfig.h" 
#import "AdWhirlView.h" 
#import "AdWhirlLog.h" 
#import "AdWhirlAdNetworkAdapter+Helpers.h" 
#import "AdWhirlAdNetworkRegistry.h" 

@implementation AdWhirlAdapterIAd 

+ (AdWhirlAdNetworkType)networkType { 
    return AdWhirlAdNetworkTypeIAd; 
} 

+ (void)load { 
    if(NSClassFromString(@"ADBannerView") != nil) { 
    [[AdWhirlAdNetworkRegistry sharedRegistry] registerClass:self]; 
    } 
} 

- (void)getAd { 
    ADBannerView *iAdView = [[ADBannerView alloc] initWithFrame:CGRectZero]; 
    kADBannerContentSizeIdentifierPortrait = 
    &ADBannerContentSizeIdentifierPortrait != nil ? 
     ADBannerContentSizeIdentifierPortrait : 
     ADBannerContentSizeIdentifierPortrait; 
    kADBannerContentSizeIdentifierLandscape = 
    &ADBannerContentSizeIdentifierLandscape != nil ? 
     ADBannerContentSizeIdentifierLandscape : 
     ADBannerContentSizeIdentifierPortrait; 
    iAdView.requiredContentSizeIdentifiers = [NSSet setWithObjects: 
             kADBannerContentSizeIdentifierPortrait, 
             kADBannerContentSizeIdentifierLandscape, 
             nil]; 
    UIDeviceOrientation orientation; 
    if ([self.adWhirlDelegate respondsToSelector:@selector(adWhirlCurrentOrientation)]) { 
orientation = [self.adWhirlDelegate adWhirlCurrentOrientation]; 
    } 
    else { 
    orientation = [UIDevice currentDevice].orientation; 
    } 

    if (UIDeviceOrientationIsLandscape(orientation)) { 
    iAdView.currentContentSizeIdentifier = kADBannerContentSizeIdentifierLandscape; 
    } 
    else { 
    iAdView.currentContentSizeIdentifier = kADBannerContentSizeIdentifierPortrait; 
    } 
    [iAdView setDelegate:self]; 

    self.adNetworkView = iAdView; 
    [iAdView release]; 
} 

- (void)stopBeingDelegate { 
    ADBannerView *iAdView = (ADBannerView *)self.adNetworkView; 
    if (iAdView != nil) { 
    iAdView.delegate = nil; 
    } 
} 

- (void)rotateToOrientation:(UIInterfaceOrientation)orientation { 
    ADBannerView *iAdView = (ADBannerView *)self.adNetworkView; 
    if (iAdView == nil) return; 
    if (UIInterfaceOrientationIsLandscape(orientation)) { 
    iAdView.currentContentSizeIdentifier = kADBannerContentSizeIdentifierLandscape; 
    } 
    else { 
    iAdView.currentContentSizeIdentifier = kADBannerContentSizeIdentifierPortrait; 
    } 
    // ADBanner positions itself in the center of the super view, which we do not 
    // want, since we rely on publishers to resize the container view. 
    // position back to 0,0 
    CGRect newFrame = iAdView.frame; 
    newFrame.origin.x = newFrame.origin.y = 0; 
    iAdView.frame = newFrame; 
} 

- (BOOL)isBannerAnimationOK:(AWBannerAnimationType)animType { 
    if (animType == AWBannerAnimationTypeFadeIn) { 
    return NO; 
    } 
    return YES; 
} 

- (void)dealloc { 
    [super dealloc]; 
} 

#pragma mark IAdDelegate methods 

- (void)bannerViewDidLoadAd:(ADBannerView *)banner { 
    // ADBanner positions itself in the center of the super view, which we do not 
    // want, since we rely on publishers to resize the container view. 
    // position back to 0,0 
    CGRect newFrame = banner.frame; 
    newFrame.origin.x = newFrame.origin.y = 0; 
    banner.frame = newFrame; 

    [adWhirlView adapter:self didReceiveAdView:banner]; 
} 

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error { 
    [adWhirlView adapter:self didFailAd:error]; 
} 

- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:    (BOOL)willLeave { 
    [self helperNotifyDelegateOfFullScreenModal]; 
    return YES; 
} 

- (void)bannerViewActionDidFinish:(ADBannerView *)banner { 
    [self helperNotifyDelegateOfFullScreenModalDismissal]; 
} 

@end 

这里就是广告被称为应用

MainMenuInterface.h

#import <Foundation/Foundation.h> 
#import "cocos2d.h" 
#import "GameManager.h" 
#import "AdWhirlView.h" 
#import "AdWhirlDelegateProtocol.h" 
#import "Reading_FluencyAppDelegate.h" 
#import "RootViewController.h" 

enum GameStatePP { 
    kGameStatePlaying, 
    kGameStatePaused 
}; 


@interface MainMenuInterface : CCLayer <AdWhirlDelegate> 

{ 
    CCMenu *mainMenu; 
    CCMenu *aboutPage; 

    RootViewController *viewController; 
    AdWhirlView *adWhirlView; 
    enum GameStatePP _state; 
} 

@property(nonatomic,retain) AdWhirlView *adWhirlView; 
@property(nonatomic) enum GameStatePP state; 

-(void)displayStartButton; 

@end 

这里是MainMenuInterface.m重要的东西

- (void)adWhirlWillPresentFullScreenModal { 

    if (self.state == kGameStatePlaying) { 

     //[[SimpleAudioEngine sharedEngine] pauseBackgroundMusic]; 

     [[CCDirector sharedDirector] pause]; 
    } 
} 

- (void)adWhirlDidDismissFullScreenModal { 

    if (self.state == kGameStatePaused) 
     return; 

    else { 
     self.state = kGameStatePlaying; 
     //[[SimpleAudioEngine sharedEngine] resumeBackgroundMusic]; 
     [[CCDirector sharedDirector] resume]; 

    } 
} 

- (NSString *)adWhirlApplicationKey { 
    return @"23myapplicationkey39203924"; 
} 

- (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]; 

} 

-(void)onEnter { 
    viewController = [(Reading_FluencyAppDelegate *)[[UIApplication sharedApplication]   delegate] viewController]; 
    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; 
[super dealloc]; 
} 
+0

你需要显示iAd代码来检查什么是错的。快照是不够的。 – Sumanth 2012-07-30 04:30:29

+0

更新了我认为是相关的代码。让我知道你是否需要应用代理代码。 – 2012-07-31 00:17:45

回答

0

为那些需要在未来要知道,我的问题竟然是,它在呼唤景观,而不是肖像的广告,比当它被称为adjustAdSize()它没有得到正确的大小。

我改变

- (void)adWhirlDidReceiveAd:(AdWhirlView *)adWhirlVieww { 
    [adWhirlView rotateToOrientation:UIInterfaceOrientationLandscapeRight]; 
    [self adjustAdSize]; 
{ 

- (void)adWhirlDidReceiveAd:(AdWhirlView *)adWhirlVieww { 
    [adWhirlView rotateToOrientation:UIInterfaceOrientationPortrait]; 
    [self adjustAdSize]; 
{ 

,它修好了我所有的问题!

1

也许winSize属性为您sharedDirector仍然认为你的肖像?如果你翻转它让你过:

newFrame.size.width = winSize.height; 
newFrame.origin.x = (self.adWhirlView.bounds.size.width - adSize.width)/2; 

newFrame.origin.y = (winSize.width - adSize.height); 
adWhirlView.frame = newFrame; 
+0

感谢您的反馈意见,尝试这些更改帮助我意识到这是要求横向广告尺寸,而不是纵向广告尺寸。 – 2012-07-31 22:34:28