iAd测试ADBannerViewDelegate bannerViewActionDidFinish:

时间:2012-08-24 17:52:38

标签: ios testing iad adbannerview

我想在点击完成后尝试测试bannerViewActionDidFinish:

我的经验是,在调试版本或模拟器上使用虚假广告进行测试时。有没有人能够成功测试这个?

始终使用bannerViewActionShouldBegin:willLeaveApplication:调用

willLeave == NO,当点击测试iAd时,会显示确认信息,告诉我iAd设置正确...但在关闭该窗口后,bannerViewActionDidFinish:永远不会被称为。

进一步信息:iAd横幅全部显示并在测试中正确消失,它们在应用程序商店分发构建和功能正常......直到用户从点击操作返回。我想使用bannerViewActionDidFinish:,但我看不到用假广告测试它的方法。

这是相关的代码(希望任何人都可以帮助不需要查看布局代码;根据广告是否加载到横幅中,它似乎总是在呈现或隐藏iAd横幅方面做正确的事情,或者是否发生了生成的错误,并且还匹配相应的日志输出;唯一没有发生的事情是在测试期间永远不会调用bannerViewActionDidFinish:

#pragma mark - ADBannerViewDelegate implementation
#pragma mark @optional

#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_4_3
// This method is invoked when the banner has confirmation that an ad will be presented, but
// before the ad has loaded resources necessary for presentation.
- (void)bannerViewWillLoadAd:(ADBannerView *)banner {
    if (banner == self.adBannerView)
#if DEBUG
        NSLog(@"(%@)bannerViewWillLoadAd", self.navigationItem.title),
#endif
        banner.hidden = NO;
#if DEBUG
    else
        NSLog(@"== banner that will load ad is different than this view's banner ==");
#endif
}
#endif

// This method is invoked each time a banner loads a new advertisement. Once a banner has
// loaded an ad, it will display that ad until another ad is available. The delegate might
// implement this method if it wished to defer placing the banner in a view hierarchy until the
// banner has content to display.
- (void)bannerViewDidLoadAd:(ADBannerView*)banner {
#if DEBUG
    NSLog(@"(%@)bannerViewDidLoadAd: bannerLoaded==%d",
          self.navigationItem.title, banner.isBannerLoaded ? 1 : 0);
#endif
    if (self.view.window)
        [UIView animateWithDuration:0.3 animations:^{
            [self.view setNeedsLayout];
            [self.view layoutIfNeeded];
        }];
#if DEBUG
    else
        NSLog(@"(%@)bannerViewDidLoadAd: window not visible, skipping …",
              self.navigationItem.title);
#endif
}

// This method will be invoked when an error has occurred attempting to get advertisement content.
// The ADError enum lists the possible error codes.
- (void)bannerView:(ADBannerView*)banner didFailToReceiveAdWithError:(NSError *)error {
#if DEBUG
    NSLog(@"(%@)%@: bannerLoaded==%d",
          self.navigationItem.title, error, banner.isBannerLoaded ? 1 : 0);
#endif
    if (self.view.window)
    {
        banner.hidden = !banner.isBannerLoaded; // can't say NO, in case banner loaded w/error!
        [UIView animateWithDuration:0.3 animations:^{
            [self.view setNeedsLayout];
            [self.view layoutIfNeeded];
        }];
    }
#if DEBUG
    else
        NSLog(@"(%@)%s window not visible, skipping…",
              self.navigationItem.title, __FUNCTION__);
#endif
}

// This message will be sent when the user taps on the banner and some action is to be taken.
// Actions either display full screen content in a modal session or take the user to a different
// application. The delegate may return NO to block the action from taking place, but this
// should be avoided if possible because most advertisements pay significantly more when
// the action takes place and, over the longer term, repeatedly blocking actions will
// decrease the ad inventory available to the application. Applications may wish to pause video,
// audio, or other animated content while the advertisement's action executes.

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


// This message is sent when a modal action has completed and control is returned to the
// application.  Games, media playback, and other activities that were paused in response to the
// beginning of the action should resume at this point.

- (void)bannerViewActionDidFinish:(ADBannerView *)banner {
    // all new code, to be tested
    [self configureView];
    [UIView animateWithDuration:0.3 animations:^{
        [self.view setNeedsLayout];
        [self.view layoutIfNeeded];
    }];
}

0 个答案:

没有答案