我的 iAd 代码有问题吗?
Is there something wrong is my iAd code?
我的应用程序几天前才获得批准,并且在屏幕底部有一个 iAd 横幅。我知道广告最多可能需要一周的时间才能开始展示,但在我等待的过程中..有人可以确保我的代码没有任何错误吗?
import UIKit
import SpriteKit
import iAd
import GameKit
class GameViewController: UIViewController, ADBannerViewDelegate, GKLocalPlayerListener {
var adBanner: ADBannerView!
override func viewDidLoad() {
super.viewDidLoad()
authenticateLocalPlayer()
if let scene = GameScene(fileNamed:"GameScene") {
// Configure the view.
let skView = self.view as! SKView
skView.ignoresSiblingOrder = true
scene.scaleMode = .AspectFill
skView.presentScene(scene)
}
}
func loadBanner() {
adBanner = ADBannerView(frame: CGRect.zero)
adBanner.center = CGPoint(x: adBanner.center.x, y: view.bounds.size.height - adBanner.frame.size.height / 2)
adBanner.delegate = self
adBanner.hidden = true
view.addSubview(adBanner)
}
func bannerViewDidLoadAd(banner: ADBannerView!) {
adBanner.hidden = false
}
func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
adBanner.hidden = true
}
func bannerViewActionShouldBegin(banner: ADBannerView!, willLeaveApplication willLeave: Bool) -> Bool {
return true
}
override func shouldAutorotate() -> Bool {
return true
}
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
return .AllButUpsideDown
} else {
return .All
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Release any cached data, images, etc that aren't in use.
}
override func prefersStatusBarHidden() -> Bool {
return true
}
func authenticateLocalPlayer() {
let localPlayer = GKLocalPlayer.localPlayer()
localPlayer.authenticateHandler = {(viewController, error) -> Void in
if (viewController != nil) {
self.presentViewController(viewController!, animated: true, completion: nil)
}
else {
print((GKLocalPlayer.localPlayer().authenticated))
}
}
}
}
现在它只显示一个白色矩形。我的代码有什么问题吗,还是我只需要继续等待我的应用程序开始接收广告?
iAd 将于明天(2016 年 6 月 30 日)正式停用。我现在不确定 "sign up" 过程,但我相信 Apple 几个月前就停止注册应用程序以接收来自其网络的广告
谁叫loadBanner()
?
您可以考虑覆盖 viewDidAppear()
并将代码移到那里。
我的应用程序几天前才获得批准,并且在屏幕底部有一个 iAd 横幅。我知道广告最多可能需要一周的时间才能开始展示,但在我等待的过程中..有人可以确保我的代码没有任何错误吗?
import UIKit
import SpriteKit
import iAd
import GameKit
class GameViewController: UIViewController, ADBannerViewDelegate, GKLocalPlayerListener {
var adBanner: ADBannerView!
override func viewDidLoad() {
super.viewDidLoad()
authenticateLocalPlayer()
if let scene = GameScene(fileNamed:"GameScene") {
// Configure the view.
let skView = self.view as! SKView
skView.ignoresSiblingOrder = true
scene.scaleMode = .AspectFill
skView.presentScene(scene)
}
}
func loadBanner() {
adBanner = ADBannerView(frame: CGRect.zero)
adBanner.center = CGPoint(x: adBanner.center.x, y: view.bounds.size.height - adBanner.frame.size.height / 2)
adBanner.delegate = self
adBanner.hidden = true
view.addSubview(adBanner)
}
func bannerViewDidLoadAd(banner: ADBannerView!) {
adBanner.hidden = false
}
func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
adBanner.hidden = true
}
func bannerViewActionShouldBegin(banner: ADBannerView!, willLeaveApplication willLeave: Bool) -> Bool {
return true
}
override func shouldAutorotate() -> Bool {
return true
}
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
return .AllButUpsideDown
} else {
return .All
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Release any cached data, images, etc that aren't in use.
}
override func prefersStatusBarHidden() -> Bool {
return true
}
func authenticateLocalPlayer() {
let localPlayer = GKLocalPlayer.localPlayer()
localPlayer.authenticateHandler = {(viewController, error) -> Void in
if (viewController != nil) {
self.presentViewController(viewController!, animated: true, completion: nil)
}
else {
print((GKLocalPlayer.localPlayer().authenticated))
}
}
}
}
现在它只显示一个白色矩形。我的代码有什么问题吗,还是我只需要继续等待我的应用程序开始接收广告?
iAd 将于明天(2016 年 6 月 30 日)正式停用。我现在不确定 "sign up" 过程,但我相信 Apple 几个月前就停止注册应用程序以接收来自其网络的广告
谁叫loadBanner()
?
您可以考虑覆盖 viewDidAppear()
并将代码移到那里。