1

我正在尝试在我的免费版应用程序上放置一个 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;
}
4

1 回答 1

0

in this case, you can check the willLeave: argument of bannerViewActionShouldBegin:willLeaveApplication:

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

    [buttonTest setEnabled:!willLeave];

    return YES;
}

this way, buttonTest remains enabled if you don't leave the application for the iAd click-through.

于 2012-08-24T17:29:21.990 回答