我已将iAd导入我的GameScene.swift
文件中,由于某种原因我无法调用self.canDisplayBannerAds()
方法。有谁知道如何解决这个问题?
答案 0 :(得分:1)
以下是一些适用于我的工作代码。这不需要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 */
}
答案 1 :(得分:0)
如果您想使用canDisplayBannerAds
,请执行以下操作:
import UIKit
import iAd // Import iAd
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
showBanner()
}
func showBanner() {
// Creates a self managed ADBannerView
self.canDisplayBannerAds = true
}
func hideBanner() {
// Removes the ADBannerView
self.canDisplayBannerAds = false
}
使用canDisplayBannerAds
为您创建和管理ADBannerView
。没有必要实现其他方法,ADBannerView
将隐藏/显示自己,具体取决于是否有可用的广告。
答案 2 :(得分:-1)
您是否记得从ADBannerViewDelegate
AND import iAd
yourVC: UIViewController, ADBannerViewDelegate {
...
}