2011-05-07 2 views
1

애플리케이션이 시작되면 iAd는 첫 번째 화면에 광고를로드하지 않습니다. 오류 메시지가 없으며 아무것도 표시되지 않습니다. 화면을 전환하면 (다른 화면으로 이동) 처음 화면으로 돌아가더라도 광고가 게재되고 게재됩니다.내 애플리케이션이 처음 시작될 때 iAd가 첫 번째 화면에 광고를로드하지 않습니다.

ApplicationDelegate에있는 단일 iAd 인스턴스를 사용하고 있습니다. viewDidAppear의 iAdBanner에서 링크를 시도하고 viewWillDisappear에서 링크를 해제하려고합니다.

viewDidAppear 방법 :

- (void)viewDidAppear:(BOOL)animated 
{ 
    NSLog(@"view did appear"); 
    [super viewDidAppear:animated]; 

    ADBannerView *adBanner = SharedAdBannerView; 

    adBanner.requiredContentSizeIdentifiers = (&ADBannerContentSizeIdentifierPortrait != nil) ? 
    [NSSet setWithObjects:ADBannerContentSizeIdentifierPortrait, ADBannerContentSizeIdentifierLandscape, nil] : 
    [NSSet setWithObjects:ADBannerContentSizeIdentifier320x50, ADBannerContentSizeIdentifier480x32, nil]; 


    [self.view addSubview:adBanner]; 
    // set the delegate to self, so that we are notified of ad responses 
    [adBanner setDelegate:self]; 
    isAdShown = [adBanner isBannerLoaded]; 
    [self layoutForCurrentOrientation:animated]; 
} 

레이아웃 방법 :

- (void)layoutForCurrentOrientation:(BOOL)animated 
{ 
    //TODO: this only handles bottom-located elements 


    ADBannerView *adBanner = SharedAdBannerView; 

    CGFloat animationDuration = animated ? 0.2f : 0.0f; 
    // by default content consumes the entire view area 
    CGRect contentFrame = contentView.bounds; 
    CGRect owningViewFrame = [self view].bounds; 
    // the banner still needs to be adjusted further, but this is a reasonable starting point 
    // the y value will need to be adjusted by the banner height to get the final position 
    CGPoint bannerOrigin = CGPointMake(CGRectGetMinX(owningViewFrame), CGRectGetMaxY(owningViewFrame)); 
    CGFloat bannerHeight = 0.0f; 

    // First, setup the banner's content size and adjustment based on the current orientation 
    if(UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) 
     adBanner.currentContentSizeIdentifier = (&ADBannerContentSizeIdentifierLandscape != nil) ? ADBannerContentSizeIdentifierLandscape : ADBannerContentSizeIdentifier480x32; 
    else 
     adBanner.currentContentSizeIdentifier = (&ADBannerContentSizeIdentifierPortrait != nil) ? ADBannerContentSizeIdentifierPortrait : ADBannerContentSizeIdentifier320x50; 
    bannerHeight = adBanner.bounds.size.height; 

    // Depending on if the banner has been loaded, we adjust the content frame and banner location 
    // to accomodate the ad being on or off screen. 
    // This layout is for an ad at the bottom of the view. 
    if (isAdShown) 
    { 
     NSLog(@"Banner is loaded"); 
     contentFrame.size.height = owningViewFrame.size.height - bannerHeight; 
     bannerOrigin.y -= bannerHeight; 
    } 
    else 
    { 
     NSLog(@"Banner is not loaded"); 
     bannerOrigin.y += bannerHeight; 
     contentFrame.size.height = owningViewFrame.size.height; 
    } 
    NSLog(@"Banner content Frame: (%f, %f), (%f, %f)", bannerOrigin.x, bannerOrigin.y, contentFrame.size.width, contentFrame.size.height); 
    // And finally animate the changes, running layout for the content view if required. 
    [UIView animateWithDuration:animationDuration 
        animations:^{ 
         contentView.frame = contentFrame; 
         [contentView layoutIfNeeded]; 
         adBanner.frame = CGRectMake(bannerOrigin.x, bannerOrigin.y, adBanner.frame.size.width, adBanner.frame.size.height); 
        }]; 
} 

와 viewWillDisappear 방법 :

-(void)viewWillDisappear:(BOOL)animated 
{ 
    NSLog(@"View will disappear"); 
    [super viewWillDisappear:animated]; 
    [self removeLinkToAdBanner:animated]; 
} 
-(void)removeLinkToAdBanner:(BOOL)animated 
{ 
    ADBannerView *adBanner = SharedAdBannerView; 
    if ([adBanner delegate] == self) { 
     adBanner.delegate = nil; 
     [adBanner removeFromSuperview]; 
    } 
} 

진짜 불만이 내가 전에 시뮬레이터에서 일 하였다 xcode 4로 업그레이드되었습니다. 업그레이드 된 후 갑자기 작동이 멈췄습니다. 다른 사람이 이런 행동을 본적이 있습니까? 내가 고칠 수있는 아이디어? 문제는 시뮬레이터에서 4.x의 모든 테스트 버전 (4.0 ~ 4.3)에서 발생합니다.

+0

아마 또한 내가 그 분 동안 앉아 보자 있고, 전혀 말게 위임에 대한 호출, 또는 기본보기를 변경 보지 못한 점에 유의해야하지만 그 순간 나는로 이동 다른보기, 그것은 올바르게 작동하기 시작합니다. – aperkins

+0

'SharedAdBannerView'는 어떻게 정의되어 있습니까? –

+0

#define SharedAdBannerView ((VNApplicationDelegate *) [[UIApplication sharedApplication] delegate]). adBanner 여기서 VNApplicationDelegate는 내 응용 프로그램 대리자입니다. – aperkins

답변

2

동일한 문제가 발생하여 AppDelegate의 bannerViewDidLoadAd 메서드에 수정 사항이 있습니다. 처음에 광고를 표시하려면 showBanner 메소드를 호출해야합니다.

- (void)bannerViewDidLoadAd:(ADBannerView *)banner 
{ 
    [_currentController showBannerView:_bannerView animated:YES]; 
} 

새로운 iAdSuite 샘플 코드를 확인하십시오.

iAdSuite Sample Code Updated 10/31/11

+0

정보를 보내 주셔서 감사합니다. – aperkins

관련 문제