Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iAds interfering functionality of Swift app

Tags:

ios

swift

iad

Since I have enabled iAds in my trivia app, the background, which is supposed to change every time a new question is loaded no longer changes. When I comment out the canDisplayBannerAds line, it works again. Any ideas as to what could be wrong?

import UIKit
import iAd

class ViewController: UIViewController {

    @IBOutlet weak var funFactLabel: UILabel!

    @IBOutlet weak var funFactButton: UIButton!
    let factBook = FactBook()
    let colorWheel = ColorWheel()

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        funFactLabel.text = factBook.randomFact()
        self.canDisplayBannerAds = true
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    @IBAction func showFunFact() {
        let randomColor = colorWheel.randomColor()
        view.backgroundColor = randomColor
        funFactButton.tintColor = randomColor
        funFactLabel.text = factBook.randomFact()
    }

}
like image 505
user3375766 Avatar asked Nov 27 '25 07:11

user3375766


1 Answers

Rather than using view.backgroundColor = randomColor you should be using originalContentView.backgroundColor = randomColor


How I got the solution:

From the documentation for canDisplayBannerAds

See Also

originalContentView

And originalContentView says:

When a view controller enables banner ads, the system puts the view controller’s content view inside of a new content view that the system manages. This allows the system to dynamically resize the original content view when a banner ad is displayed, as well as managing the display of the banner ad itself. This property provides access to the original content view, rather than the containing view that manages banner ad display.

like image 200
David Skrundz Avatar answered Nov 28 '25 21:11

David Skrundz