Itβs relatively cleaner and easier to follow the Interstitial Ads implementation method, since this method does not require the use of NSNotificationCentre
import UIKit import iAd class ViewController: UIViewController, ADInterstitialAdDelegate { var interstitialAd:ADInterstitialAd! var interstitialAdView: UIView = UIView() override func viewDidLoad() { super.viewDidLoad() loadInterstitialAd() } func loadInterstitialAd() { interstitialAd = ADInterstitialAd() interstitialAd.delegate = self } func interstitialAdWillLoad(interstitialAd: ADInterstitialAd!) { } func interstitialAdDidLoad(interstitialAd: ADInterstitialAd!) { interstitialAdView = UIView() interstitialAdView.frame = self.view.bounds view.addSubview(interstitialAdView) interstitialAd.presentInView(interstitialAdView) UIViewController.prepareInterstitialAds() } func interstitialAdActionDidFinish(interstitialAd: ADInterstitialAd!) { interstitialAdView.removeFromSuperview() } func interstitialAdActionShouldBegin(interstitialAd: ADInterstitialAd!, willLeaveApplication willLeave: Bool) -> Bool { return true } func interstitialAd(interstitialAd: ADInterstitialAd!, didFailWithError error: NSError!) { } func interstitialAdDidUnload(interstitialAd: ADInterstitialAd!) { interstitialAdView.removeFromSuperview() }
And this can help if you put println("Function Name") in each function just to track the process of interstitial ads. If you have any questions or a way to improve this block of code, please leave a comment. Thank you.
source share