【问题标题】:iAd banner ad is not working because of the following error (Sprite Kit)由于以下错误(Sprite Kit),iAd 横幅广告无法正常工作
【发布时间】:2016-01-31 04:21:14
【问题描述】:

我正在使用精灵套件,我希望横幅广告显示在我的所有场景中。我不想使用 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)
    }
}

【问题讨论】:

    标签: swift sprite-kit iad


    【解决方案1】:

    我遇到了同样的问题,并通过使用横幅广告的自动模式解决了这个问题。只需在您的 ViewController 中设置“canDisplayBannerAds”,Apple 就会关心实例的数量:

    class GameViewController: UIViewController {
    
        override func viewDidLoad() {
            super.viewDidLoad()
            self.canDisplayBannerAds = true
    
    ...
    

    【讨论】:

    • 欢迎堆栈溢出。如果您不知道:回答的人会在空闲时间这样做,唯一的动机就是提供帮助。你的回答可以被认为有点粗鲁。顺便说一句:我不会继续使用 iAD。它将于 2016 年年中被 Apple 停产
    猜你喜欢
    • 2014-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多