由于以下错误(精灵套件),iAd横幅广告无效

时间:2016-01-31 04:21:14

标签: swift sprite-kit iad

我正在使用精灵套件,我希望横幅广告能够显示在我的所有skscenes上。我不想使用self.candisplaybannerads因为它在游戏中推动我的场景并导致它在游戏中导致死亡。

以下是错误:警告:当前存在超过10个ADBannerView或ADInterstitialView实例。这是对iAd API的误用,因此广告效果会受到影响。此消息仅打印一次。

这是我的代码:

import UIKit
import iAd
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, ADBannerViewDelegate {

var window: UIWindow?
var AdBanner = ADBannerView()

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {

    // Override point for customization after application launch.
    UIViewController.prepareInterstitialAds()

    /* Ad Banner Settings */
    AdBanner = ADBannerView()
    AdBanner.frame = CGRectZero
    AdBanner.delegate = self
    AdBanner.backgroundColor = UIColor.clearColor()

    /* 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 */
    }


    return true
}

以下是我调用横幅广告的位置

class GameViewController: UIViewController {

let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate

override func viewDidLoad() {
    super.viewDidLoad()
    appDelegate.AdBanner.frame = CGRectMake(0, self.view.frame.size.height-appDelegate.AdBanner.frame.size.height, appDelegate.AdBanner.frame.size.width, appDelegate.AdBanner.frame.size.height)
    self.view .addSubview(appDelegate.AdBanner)

    //authenticateLocalPlayer()

    if let scene = StartScreen(fileNamed:"StartScreen") {
        // Configure the view.
        let skView = self.view as! SKView
        skView.showsFPS = false
        skView.showsNodeCount = false

        /* 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)
    }
}

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,并通过横幅广告的自动模式解决了这个问题。只需设置“canDisplayBannerAds'在ViewController中,Apple负责实例的数量:

class GameViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.canDisplayBannerAds = true

...