iAd与SpriteKit中的Swift [英] iAd's with Swift in SpriteKit
问题描述
我正在开发一个应用,并且希望包含iAd.我设法添加了横幅广告,它们运作良好.但是,我想添加一个较大的内容,以填充整个屏幕的大部分,但不能填充全屏.我使用 Benzene的问题和erdekhayser提供的解决方案中的代码添加了adBanner.
I am working on an app and would like to include iAd's. I have managed to add banner ad's and they work well. However i want to a larger add that fills most of the screen but not full screen. I added the adBanner using code from Benzene's Question and given solution from erdekhayser.
我上面引用的链接来自Apple文档,Apple将iAd称为MREC广告.这就是我想要的.我不知道如何创建和添加一个.我已经尝试过调整adBanner的大小,但仍然无法弄清楚.
The link i have referenced above is from the apple documentation and apple refer to the iAd as an MREC ad. This is what i would like to have. I cannot work out how to create and add one though. I have tried resizing the adBanner but still cannot figure it out.
任何帮助将不胜感激
这是我到目前为止的代码:
This is the code i have so far:
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")
}
推荐答案
将canDisplayBannerAds
设置为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)
}
这篇关于iAd与SpriteKit中的Swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!