IAd with Swift in SpriteKit

I am working on an application and would like to enable iAd. I managed to add a banner ad and they work well. However, I want to add a larger add-on that fills most of the screen, but not full-screen. I added adBanner using the code from the Benzel Question and this solution from erdekhayser.

Apple iAd Documentation (Page 3)

The link I referenced above is derived from the documentation for the apple, and the apple refers to the iAd as an MREC declaration. This is what I would like to have. I can’t figure out how to create and add one. I tried to resize the ad unit, but still can't figure it out.

Any help would be appreciated

This is the code that I still have:

import UIKit import SpriteKit import iAd import Twitter var adBannerView: ADBannerView! class GameViewController: UIViewController, ADBannerViewDelegate { var scene: GameScene! func loadAds() { adBannerView = ADBannerView(frame: CGRectZero) adBannerView.delegate = self adBannerView.hidden = true view.addSubview(adBannerView) } override func viewDidLoad() { super.viewDidLoad() // Configure the view. let skView = view as SKView skView.showsFPS = false skView.showsNodeCount = true skView.showsPhysics = false /* Sprite Kit applies additional optimizations to improve rendering performance */ skView.ignoresSiblingOrder = true /* Set the scale mode to scale to fit the window */ scene = GameScene(size: skView.bounds.size) scene.scaleMode = .AspectFill skView.presentScene(scene) //iAd loadAds() } //iAd func bannerViewWillLoadAd(banner: ADBannerView!) { println("Ad about to load") } func bannerViewDidLoadAd(banner: ADBannerView!) { adBannerView.center = CGPoint(x: adBannerView.center.x, y: view.bounds.size.height - view.bounds.size.height + adBannerView.frame.size.height / 2) adBannerView.hidden = false println("Displaying the Ad") } func bannerViewActionDidFinish(banner: ADBannerView!) { println("Close the Ad") } func bannerViewActionShouldBegin(banner: ADBannerView!, willLeaveApplication willLeave: Bool) -> Bool { //pause game here println("Leave the application to the Ad") return true } func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) { //move off bounds when add didnt load adBannerView.center = CGPoint(x: adBannerView.center.x, y: view.bounds.size.height + view.bounds.size.height) println("Ad is not available") } 
+1
source share
1 answer

Set canDisplayBannerAds to true.

 override func viewDidLoad() { super.viewDidLoad() // Configure the view. let skView = self.originalContentView as! SKView loadAds() self.canDisplayBannerAds = true // <-- skView.showsFPS = false skView.showsNodeCount = true skView.showsPhysics = false /* Sprite Kit applies additional optimizations to improve rendering performance */ skView.ignoresSiblingOrder = true /* Set the scale mode to scale to fit the window */ scene = GameScene(size: skView.bounds.size) scene.scaleMode = .AspectFill skView.presentScene(scene) 

}

+2
source

Source: https://habr.com/ru/post/1210515/


All Articles