0

I've been trying to figure out how to implement a portrait banner ad view at the bottom of my Sprite Kit game with Swift and am quite confused as to how to do it.

My references were the iAd Guide from Apple, which is unfortunately in Obj-C(I'm new to the whole programming scene so forgive my ignorance of Obj-C), as well as these: iAd in sprite kit game

iAd in xcode 6 with Swift

http://codewithchris.com/iad-tutorial/

If anyone could suggest a method I would be really grateful to you, thanks for reading :)

Community
  • 1
  • 1
Sam Lee
  • 65
  • 8

1 Answers1

0

Code with AutoLayout(code in viewDidLoad()):

    let bannerAd = ADBannerView(adType: ADAdType.Banner)
    bannerAd.delegate = self
    bannerAd.setTranslatesAutoresizingMaskIntoConstraints(false)
    self.view.addSubview(bannerAd)
    let constraintsH = NSLayoutConstraint.constraintsWithVisualFormat("|[bannerAd]|", options: nil, metrics: nil, views: ["bannerAd":bannerAd])
    let constraintsV = NSLayoutConstraint.constraintsWithVisualFormat("V:[bannerAd(50)]|", options: nil, metrics: nil, views: ["bannerAd":bannerAd])
    self.view.addConstraints(constraintsH)
    self.view.addConstraints(constraintsV)

Don't forget to implement delegate methods.

duan
  • 8,515
  • 3
  • 48
  • 70
  • Thank you very much, before looking at your solution, i added a line of code in my viewdidload which was: self.canDisplayBannerAds = true, and surprisingly when i tested my app an iAd banner showed up at the bottom of the screen where i wanted it to – Sam Lee Mar 02 '15 at 12:26