2012-07-30 65 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