iOS 9.2.1, Xcode 7.2.1, ARC enabled
I am using the old method:
[interstitial presentFromViewController:self]
Otherwise, the status bar is still displayed using the container view for the view, and there is no “X” button, or you are not receiving any callbacks using the suggested Apple methods, i.e.
[self requestInterstitialAdPresentation]; [interstitial presentInView:self.view];
You can suppress warnings if this bothers you:
#pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations"
Please read this post: iOS 7 iAd interstitial ads cannot be closed by user
What I am doing is attaching a presentation in this method, adding some policy with some conditions:
*. H
#import <UIKit/UIKit.h> #import <iAd/iAd.h> #import <AssetsLibrary/AssetsLibrary.h> @interface MainViewController : UIViewController <ADInterstitialAdDelegate> { ADInterstitialAd *interstitial; } @end
* m.
- (void)viewDidLoad { [super viewDidLoad]; [UIViewController prepareInterstitialAds]; self.interstitialPresentationPolicy = ADInterstitialPresentationPolicyManual; interstitial = [[ADInterstitialAd alloc] init]; interstitial.delegate = self; } #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" - (void)presentInterlude { if (interstitial.loaded && [self shouldPresentInterstitialAd]) { [interstitial presentFromViewController:self]; } else { nil; } } #pragma clang diagnostic pop - (void)cycleInterstitial { interstitial.delegate = nil; interstitial = [[ADInterstitialAd alloc] init]; interstitial.delegate = self; } - (void)interstitialAdDidLoad:(ADInterstitialAd *)interstitialAd { NSLog(@"loaded"); nil; } - (void)interstitialAdDidUnload:(ADInterstitialAd *)interstitialAd { NSLog(@"unloaded"); [self cycleInterstitial]; } - (void)interstitialAd:(ADInterstitialAd *)interstitialAd didFailWithError:(NSError *)error { NSLog(@"failed, error: %@", error); [self cycleInterstitial]; } - (void)interstitialAdActionDidFinish:(ADInterstitialAd *)interstitialAd { NSLog(@"finish"); } - (BOOL)interstitialAdActionShouldBegin:(ADInterstitialAd *)interstitialAd willLeaveApplication:(BOOL)willLeave { NSLog(@"action"); return true; } @end
Then use [self presentInterlude] when you are ready to submit an interstitial ad.
To indicate when an ad is displayed and when the ad is closed using the "X" button (without clicking the contents of the ad by the user), you should take advantage of the fact that when the ad is viewDidDissapear: and when the ad is closed viewDidAppear: If you have content that needs to be ready before calling viewDidAppear: use the viewWillAppear: method.
Remember to include the interstitial cycle after each presentation, the interstitial ad will be released after the presentation, which represents the biggest difference between an interstitial ad and a banner type ad.
If anyone has a better solution, please share and send a message!
Thanks! Greetings.