4

my iAd-integration does not work correctly. I tried to implement fullscreen ads. The ad appears but when I press the "X"-button to close, it does not close.

Maybe you can find an Issue in my code? I don't know what to change and have invested a lot of time in fixing the issue without success.

UPDATE

it works with [interstitial presentFromViewController:self]; but not with [interstitial presentInView:self.view]; The problem is that presentFromViewController is deprecated with iOS 7...so how do I have to change it?


- (void)viewDidLoad
    {
        requestingAd = NO;
        [self showFullScreenAd];

    }

//Interstitial iAd
    -(void)showFullScreenAd {
        //Check if already requesting ad
        if (requestingAd == NO) {
            interstitial = [[ADInterstitialAd alloc] init];
            interstitial.delegate = self;
            self.interstitialPresentationPolicy = ADInterstitialPresentationPolicyManual;
            [self requestInterstitialAdPresentation];
            NSLog(@"interstitialAdREQUEST");
            requestingAd = YES;
        }//end if
    }

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

    -(void)interstitialAdDidLoad:(ADInterstitialAd *)interstitialAd {
        NSLog(@"interstitialAdDidLOAD");
        if (interstitialAd != nil && interstitial != nil && requestingAd == YES) {
    [interstitial presentInView:self.view];
            NSLog(@"interstitialAdDidPRESENT");
        }//end if
    }

    -(void)interstitialAdDidUnload:(ADInterstitialAd *)interstitialAd {
        interstitial = nil;
        requestingAd = NO;
        NSLog(@"interstitialAdDidUNLOAD");
    }

    -(void)interstitialAdActionDidFinish:(ADInterstitialAd *)interstitialAd {
        interstitial = nil;
        requestingAd = NO;
        NSLog(@"interstitialAdDidFINISH");
    }

Thank you in advance :)

user3430458
  • 41
  • 1
  • 4

2 Answers2

4

I had the same issue. Not sure if you've figured this out yet, but there's actually no need to presentInView.

All you need to call is [self requestInterstitialAdPresentation]. HOWEVER... if an ad is not loaded, it will not show in the view, and will not give you a log or warning similar to the old iAd API.

My best advice is before you load the view, from wherever you call the view controller to be loaded, that is where you set the Presentation Policy. My other bit of advice, is to call [UIView prepareInterstitialAds] in the AppDelegate. It gives a better probability of an Ad being loaded before you request an ad.

Hope that helps. Good luck.

Bhumit Mehta
  • 16,278
  • 11
  • 50
  • 64
RobMillerJ25
  • 616
  • 5
  • 6
  • 1
    This is wrong. The class method `prepareInterstitialAds` is a UIViewController class method:https://developer.apple.com/library/iOs/documentation/iAd/Reference/UIViewController_iAd_Additions/index.html – Danny S Sep 23 '14 at 18:58
  • I did forget the Controller after the UIView, but it's not incorrect, I use it in this instance and it works perfectly, replacing UIViewController with the name of the view controller being used. – RobMillerJ25 Sep 24 '14 at 20:47
  • I didn't say the use of the method is incorrect. I said is incorrect the class on which you were saying to call it :) – Danny S Sep 24 '14 at 22:34
4

The best solution of this problem for me was to replace [interstitial presentInView:self.view]; with [_interstitialAd presentInView:_adPlaceholderView]; where _adPlaceholderView is view with same bounds as self.view and added just before showing the ad. And don't forget to remove this view after ad was finished.

The finished methods will looks like this:

-(void)interstitialAdDidLoad:(ADInterstitialAd *)interstitialAd
{
    if ((interstitialAd != nil) && (_interstitialAd != nil) && (_requestingAd))
    {
        _adPlaceholderView = [[UIView alloc] initWithFrame:self.view.bounds];
        [self.view addSubview:_adPlaceholderView];
        [_interstitialAd presentInView:_adPlaceholderView];
    }
}

-(void)interstitialAdActionDidFinish:(ADInterstitialAd *)interstitialAd
{
    _interstitialAd = nil;
    _requestingAd = NO;
    [_adPlaceholderView removeFromSuperview];
    _adPlaceholderView = nil;
}

I hope it will help you too.

alokard
  • 79
  • 3