Interstitial Iad - Close button

Asked

Viewed 71 times

1

I’m trying to include a fullscreen Iad in an app, but the advertising screen is appearing without the close button, the doubt is whether I have to do it by hand or has some hidden option for it?

I found older things about it, but I don’t know if they still reflect the current reality.

Follows the base of the code I’m using, but in a file "empty".

import UIKit
import iAd

class ViewController: UIViewController, ADInterstitialAdDelegate{

    var interstitialAd:ADInterstitialAd!
    var interstitialAdView: UIView = UIView()

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }

    @IBAction func chamarIAd(sender: AnyObject) {
        loadInterstitialAd()
    }

    func loadInterstitialAd() {
        println("loadInterstitialAd")
        interstitialAd = ADInterstitialAd()
        interstitialAd.delegate = self
    }

    func interstitialAdWillLoad(interstitialAd: ADInterstitialAd!) {
        println("interstitialAdWillLoad")
    }

    func interstitialAdDidLoad(interstitialAd: ADInterstitialAd!) {
        println("interstitialAdDidLoad")

        interstitialAdView = UIView()
        interstitialAdView.frame = self.view.bounds
        view.addSubview(interstitialAdView)

        interstitialAd.presentInView(interstitialAdView)
        UIViewController.prepareInterstitialAds()
    }

    func interstitialAdActionDidFinish(interstitialAd: ADInterstitialAd!) {
        println("interstitialAdActionDidFinish")
        interstitialAdView.removeFromSuperview()
    }

    func interstitialAdActionShouldBegin(interstitialAd: ADInterstitialAd!, willLeaveApplication willLeave: Bool) -> Bool {
        println("interstitialAdActionShouldBegin")
        return true
    }

    func interstitialAd(interstitialAd: ADInterstitialAd!, didFailWithError error: NSError!) {
        println("interstitialAd")
    }

    func interstitialAdDidUnload(interstitialAd: ADInterstitialAd!) {
        println("interstitialAdDidUnload")
        interstitialAdView.removeFromSuperview()
    }
}

1 answer

1


I believe I have solved my problem. I will leave here for the question to have an answer and in case someone has a better solution.

  • I created the close button inside the viewDidLoad method:

    override func viewDidLoad() {
        super.viewDidLoad()
    
        closeButton = UIButton(frame: CGRect(x: 10, y:  20, width: 20, height: 20))
        closeButton.setBackgroundImage(UIImage(named: "close_button"), forState: UIControlState.Normal)
        closeButton.addTarget(self, action: Selector("close"), forControlEvents: UIControlEvents.TouchUpInside)
    }
    
  • When Iad is being pressed, I add the close button in the view:

    func interstitialAdDidLoad(interstitialAd: ADInterstitialAd!) {
        interstitialAdView = UIView()
        interstitialAdView.frame = self.view.bounds
        view.addSubview(interstitialAdView)
    
        interstitialAd.presentInView(interstitialAdView)
        UIViewController.prepareInterstitialAds()
    
        view.addSubview(closeButton)
    }
    
  • I created the button method by removing Iad and the close button from the main view:

    func close() {
        interstitialAdView.removeFromSuperview()
        closeButton.removeFromSuperview()   
    }
    

Browser other questions tagged

You are not signed in. Login or sign up in order to post.