我正在努力在场景中实现横幅广告,但它始终报告“线程1:EXC_BREAKPOINT(代码= EXC_ARM_BREAKPOINT,子代码= Oxdefe),程序停止运行.
我在关于iAd(“ Swift – ADBannerView”)的另一个问题中引用了 Mr. T’s answer,但仍然无法做到.
我在关于iAd(“ Swift – ADBannerView”)的另一个问题中引用了 Mr. T’s answer,但仍然无法做到.
代码如下所示:
import UIKit
import SpriteKit
import iAd
class GameViewController: UIViewController,ADBannerViewDelegate {
@IBOutlet var adBannerView: ADBannerView
override func viewDidLoad() {
super.viewDidLoad()
println("view loaded")
//iAd
self.candisplayBannerAds = true
self.adBannerView.delegate = self
self.adBannerView.alpha = 0.0
if let scene = GameScene.unarchiveFromFile("GameScene") as? GameScene {
// Configure the view.
let skView = self.view as SKView
skView.showsFPS = true
skView.showsNodeCount = true
/* Sprite Kit applies additional optimizations to improve rendering performance */
skView.ignoresSiblingOrder = true
/* Set the scale mode to scale to fit the window */
scene.scaleMode = .AspectFill
skView.presentScene(scene)
}
}
//iAd
func bannerViewWillLoadAd(banner: ADBannerView!) {
println("sort of working1")
}
func bannerViewDidLoadAd(banner: ADBannerView!) {
self.adBannerView.alpha = 1.0
println("sort of working2")
}
func bannerViewActionDidFinish(banner: ADBannerView!) {
println("sort of working3")
}
func bannerViewActionShouldBegin(banner: ADBannerView!,willLeaveApplication willLeave: Bool) -> Bool {
println("sort of working4")
return true
}
func bannerView(banner: ADBannerView!,didFailToReceiveAdWithError error: NSError!) {
}
}
我在Main.storyboard中创建了一个ADBannerView,并将其与@IBOutlet adBannerView相关联.
有谁帮我搞清楚了?
这就是我做到的,可能并非所有这些都是必要的.
我没有在故事板中使用横幅,因此IBOutlet不是必需的.
此外,如果手动创建横幅,则无需设置self.candisplayBannerAds
此功能(从ObjC移植)是我展示广告的方式.
func loadAds(){
adBannerView = ADBannerView(frame: CGRect.zeroRect)
adBannerView.center = CGPoint(x: adBannerView.center.x,y: view.bounds.size.height - adBannerView.frame.size.height / 2)
adBannerView.delegate = self
adBannerView.hidden = true
view.addSubview(adBannerView)
}
这在viewDidLoad中调用.然后,在didLoadAd委托方法中,我设置了adBannerView.hidden = false,在didFailToReceiveAdWithError中,adBannerView.hidden = true
在这种情况下,我认为隐藏比alpha更好,因为它感觉更自然.我相信(但不确定)当隐藏时,GPU根本不会绘制视图,而alpha为0时,它仍然被绘制,但是不可见(如果我错了,请纠正我).
这是我的设置,它对我有用,所以希望它也适用于你的情况!