Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Interstitial iAd does not close

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 :)

like image 340
user3430458 Avatar asked Feb 14 '23 11:02

user3430458


2 Answers

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.

like image 143
alokard Avatar answered Feb 16 '23 03:02

alokard


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.

like image 33
RobMillerJ25 Avatar answered Feb 16 '23 03:02

RobMillerJ25