IAd bannerViewActionDidFinish:在测试运行视图确认关闭后未执行

时间:2012-04-12 01:58:04

标签: xcode iad adbannerview

我正在尝试在我的免费版应用上放置一个iad横幅,横幅在按下时运行顺畅,并且视图确认测试广告正确运行。但是当我关闭那个视图我的应用程序库存时,我可以按下按钮,但他们没有执行他们的操作。这就是我这样做的原因我认为bannerViewActionDidFinish:没有被调用。在bannerViewActionShouldBegin中:我设置了buttonTest setEnabled = NO,然后在bannerViewActionDidFinish:中将它设为buttonTest setEnabled = YES。结果是按钮被禁用,并且在横幅测试视图关闭时未启用。

.h文件

#import <iAd/iAd.h>

ADBannerView *adView;
BOOL bannerIsVisible;

@property (nonatomic, assign)BOOL bannerIsVisible;

.m文件

@synthesize bannerIsVisible;

- (void)viewDidLoad
{
    adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
    adView.frame = CGRectOffset(adView.frame, 0, -50);
    adView.requiredContentSizeIdentifiers = [NSSet       setWithObject:ADBannerContentSizeIdentifierLandscape];
    adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
    [self.view addSubview:adView];
    adView.delegate=self;
    self.bannerIsVisible=NO;      

    [super viewDidLoad];
}

- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
    if (!self.bannerIsVisible)
    {
        [UIView beginAnimations:@"animateAdBannerOn" context:NULL];
        banner.frame = CGRectOffset(banner.frame, 0, 50);
        [UIView commitAnimations];
        self.bannerIsVisible = YES;
    }
}

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
    if (self.bannerIsVisible)
    {
        [UIView beginAnimations:@"animateAdBannerOff" context:NULL];
        banner.frame = CGRectOffset(banner.frame, 0, -50);
        [UIView commitAnimations];
        self.bannerIsVisible = NO;
    }
}

- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave
{
    NSLog(@"Banner view is beginning an ad action");

   [buttonTest setEnabled:NO];

   return YES;
}

-(void)bannerViewActionDidFinish:(ADBannerView *)banner
{
   // resume everything you've stopped

   [buttonTest setEnabled:YES];
}

- (void)viewDidUnload
{
    adView.delegate = nil;
}

1 个答案:

答案 0 :(得分:0)

在这种情况下,您可以查看willLeave:

bannerViewActionShouldBegin:willLeaveApplication:参数
- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave
{
     NSLog(@"Banner was clicked on; will%sleave application", willLeave ? " " : " not ");

    [buttonTest setEnabled:!willLeave];

    return YES;
}

这样,如果您没有离开iAd点击的应用程序,buttonTest将保持启用状态。