Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement Interstitial iAds in Swift(Xcode 6.1)

I am trying to figure out how to switch over from my banner view iAds to interstitial iAds in order to free up space for a tabbed controller. For some reason I am completely unable to find any resource for even getting started on these ads with swift.

Could anyone please give me some information on interstitial iAds with Swift and how I can implement them in a project.

like image 882
Marcel Negrete Avatar asked Nov 28 '22 23:11

Marcel Negrete


1 Answers

Here is a relatively cleaner and easier to follow way to implement Interstitial Ads since this way doesn't 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 it may help if you put println("Function Name") in each function just to keep track of your Interstitial Ads process. If you have any questions and or a way to improve this block of code please leave a comment. Thank You

like image 149
Nylon Enterprises Avatar answered Dec 26 '22 19:12

Nylon Enterprises