Swift SpriteKit iAd

流过昼夜 提交于 2019-12-25 03:44:16

问题


I'm developing a game in Swift and I have a little problem that I couldn't solve. I'm working only with scenes, I have no UIViews. The main scene is where the game runs and when the players dies a new scene will be loaded. I want in that scene, where the player dies, to display a menu (which I did) and to display iAd banners. I tried also with UIViewControllers but I couldn't manage it. I want to make it only in SpriteKit and I don't know how. Could anybody help me please?


回答1:


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
}


来源:https://stackoverflow.com/questions/28906674/swift-spritekit-iad

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!