gpt4 book ai didi

swift - 游戏场景加载完成后如何显示iAd?

转载 作者:行者123 更新时间:2023-11-28 07:00:08 30 4
gpt4 key购买 nike

我很困惑为什么这不起作用。我收到一个错误:Thread1:SIGABRT。是的,我确实看过关于 Thread1: SIGABRT 的帖子,但它并没有解决我的问题。

如果有人能帮忙,那就太好了。它可以在没有 iAd 横幅的情况下加载。但是在程序中写iAd代码的时候,就卡住了。

import UIKit
import SpriteKit
import iAd

class GameViewController: UIViewController, ADBannerViewDelegate {

@IBOutlet var Banner: ADBannerView!

var scene: GameScene!


override func viewDidLoad() {
super.viewDidLoad()

Banner.hidden = true
Banner.delegate = self
self.canDisplayBannerAds = true

// Configure the view
let skView = view as! SKView
skView.multipleTouchEnabled = false

// Create and configure the scene
scene = GameScene(size: skView.bounds.size)
scene.scaleMode = .AspectFill

// Present the scenee
skView.presentScene(scene)


}

override func shouldAutorotate() -> Bool {
return true
}

override func supportedInterfaceOrientations() -> Int {
if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
return Int(UIInterfaceOrientationMask.AllButUpsideDown.rawValue)
} else {
return Int(UIInterfaceOrientationMask.All.rawValue)
}
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Release any cached data, images, etc that aren't in use.
}

override func prefersStatusBarHidden() -> Bool {
return true

}

func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
NSLog("Error!")
}

func bannerViewWillLoadAd(banner: ADBannerView!) {

}

func bannerViewActionShouldBegin(banner: ADBannerView!, willLeaveApplication willLeave:Bool) ->Bool {
return true
}

func bannerViewDidLoadAd(banner: ADBannerView!){
Banner.hidden = false
}
}

最佳答案

这里有一些适合你的工作代码,对我有用。这甚至不需要 self.candisplaybannerads = true 因为我对此有一些疑问。广告会根据屏幕尺寸自动改变尺寸,位于屏幕底部。

import iAd

class viewController: UIViewController, ADBannerViewDelegate {

var AdBanner = ADBannerView()

override func viewDidLoad() {
super.viewDidLoad()

/* Ad Banner Settings */

AdBanner = ADBannerView()
AdBanner.frame = CGRectZero
AdBanner.delegate = self
self.AdBanner.frame = CGRectMake(0, self.view.frame.size.height-self.AdBanner.frame.size.height, self.AdBanner.frame.size.width, self.AdBanner.frame.size.height)
AdBanner.backgroundColor = UIColor.clearColor()
self.view .addSubview(AdBanner)

}

/* All iAd Functions */

func bannerViewActionShouldBegin(banner: ADBannerView!, willLeaveApplication willLeave: Bool) -> Bool {
/* whatever you need */
return true
}

func bannerViewActionDidFinish(banner: ADBannerView!) {
/* whatever you need */
}

func bannerViewDidLoadAd(banner: ADBannerView!) {
AdBanner.hidden = false
}


func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
NSLog("Error Loading Ad")
/* whatever you need */
AdBanner.hidden = true
}
func bannerViewWillLoadAd(banner: ADBannerView!) {
/* whatever you need */
}

关于swift - 游戏场景加载完成后如何显示iAd?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32253164/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com