iAd不会调用全屏广告

时间:2015-11-19 16:01:01

标签: ios objective-c iphone iad

我已经使用iAd实现了全屏广告,但不幸的是它无法正常工作,请参阅下面的代码。

-(void)showFullScreenAd {
    if (_requestingAd == NO) {
        _interstitial = [[ADInterstitialAd alloc] init];
        _interstitial.delegate = self;
        NSLog(@"Ad Request");
        _requestingAd = YES;
    }

}

-(void)interstitialAd:(ADInterstitialAd *)interstitialAd didFailWithError:(NSError *)error {
    _requestingAd = NO;
    NSLog(@"Ad didFailWithERROR");
    NSLog(@"%@", error);
}

-(void)interstitialAdDidLoad:(ADInterstitialAd *)interstitialAd {
    NSLog(@"Ad DidLOAD");
    if (interstitialAd.loaded) {

        CGRect interstitialFrame = CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds)-90);
        interstitialFrame.origin = CGPointMake(0, 44);
        _adView = [[UIView alloc] initWithFrame:interstitialFrame];
        [self.view addSubview:_adView];

        [_interstitial presentInView:_adView];

        UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button addTarget:self action:@selector(closeAd:) forControlEvents:UIControlEventTouchDown];
        button.backgroundColor = [UIColor clearColor];
        [button setBackgroundImage:[UIImage imageNamed:@"close-button.png"] forState:UIControlStateNormal];
        button.frame = CGRectMake(0, 0, 30, 30);
        [_adView addSubview:button];

        [UIView beginAnimations:@"animateAdBannerOn" context:nil];
        [UIView setAnimationDuration:1];
        [_adView setAlpha:1];
        [UIView commitAnimations];
    }
}

-(void)closeAd:(id)sender {
    [UIView beginAnimations:@"animateAdBannerOff" context:nil];
    [UIView setAnimationDuration:1];
    [_adView setAlpha:0];
    [UIView commitAnimations];

    _adView=nil;
    _requestingAd = NO;
}

-(void)interstitialAdDidUnload:(ADInterstitialAd *)interstitialAd {
    _requestingAd = NO;
    NSLog(@"Ad DidUNLOAD");
}

-(void)interstitialAdActionDidFinish:(ADInterstitialAd *)interstitialAd {
    _requestingAd = NO;
    NSLog(@"Ad DidFINISH");
}

0 个答案:

没有答案