Sprite Kit Create an Iadbanner

Sprite Kit Create an iAdBanner

iAd has been discontinued, you will have to choose another ad provider.

From Apple's site:

The iAd App Network will be discontinued as of June 30, 2016. Although we are no longer accepting new apps into the network, advertising campaigns may continue to run and you can still earn advertising revenue until June 30.

Implementing iAd in Sprite Kit with Swift

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.

Swift SpriteKit iAd

If you simply want to display an iAd banner then you'll need to do several things. First, import the iAd framework and import iAd the the top of your code. Then, use this function to display the banner. (oh, and adBannerView should be declared as a global variables within your skscene).

func loadAds()->ADBannerView{
adBannerView = ADBannerView(frame: CGRect.zeroRect)
adBannerView.center = CGPoint(x: adBannerView.center.x, y: view!.frame.size.height - adBannerView.frame.size.height / 2)
adBannerView.delegate = self
self.view?.addSubview(adBannerView)
return adBannerView
}

You may also want to include these functions. This one right here runs when the banner cannot load (this will most likely occur due to a network problem).

func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
println("Ad cannot load")
self.adBannerView.hidden = true
}

This runs when the banner successfully loads.

func bannerViewDidLoadAd(banner: ADBannerView!) {
println("ad did load.")
self.adBannerView.hidden = false
}

How to stop Sprite Kit from reinitializing the scene with iAd banner

Thanks for the response. That was the problem. I had been initializing the scene in the viewWillLayoutSubviews method in my root view controller. I moved the scene initialization to the viewDidLoad method and it fixed the issue.

Two scenes at the same time in SpriteKit

No don't do that. Even if possible it is meaningless.

In a such case I use storyboard. Created menu at top of the screen and give the rest of the screen to SKView. By this way you can control your SKScene easily also you can use UIKit for you menu which is more advanced than SpriteKit ui elements.

Also you can use one scene and create menu nodes with SpriteKit utilities.



Related Topics



Leave a reply



Submit