由于某些原因,AdColony的AdReward无法在Swift 2.0上运行 [英] AdReward from AdColony not working on Swift 2.0 for some reason

查看:145
本文介绍了由于某些原因,AdColony的AdReward无法在Swift 2.0上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的游戏中实施奖励插页式广告,但是我遇到了很多AdColony错误,例如:广告请求未填写"或我的区域ID无效.

I would like to implement a reward interstitial in my game, but i'm getting a lot of AdColony errors such as: "No fill for ad request" or that my Zone ID is invalid.

首先,这就是我配置AdColony区域的方式:

To start of, this would be how I configured my AdColony Zone:

Zone is active? Yes

Zone Type: Preroll/Interstitial (Gives me "No fill for ad request error")
           Value Exchange/V4VC (Gives me "Zone ID invalid, please check config error")

House Ads: Back Fill

Options: 0 0 1

Development: Show Test Ads Only (Although my app is currently Live)

他们提供的SDK下载示例是针对非游戏的Apps的,因此我尝试将其翻译为游戏,尽管并没有太大区别,但是我当前的代码可能有问题. 所以这就是我在GameViewController.swift中的方式.

The example they give you with the SDK download, is for Apps not for Games so I tried to kinda translate it for Games, although it wasn't that different, but there might be a problem with my current code. So this is how I have it in my GameViewController.swift.

// Outside I declare a struct
struct Constants
{
    static let adColonyAppID = "app5aab6bb6aaf3xxxxxx"
    static let adColonyZoneID = "vz19959f95bd62xxxxxx"
    static let currencyBalance = "coinAmount"
}

// Inside GameViewController
var ad: AdColonyInterstitial?!
var spinner: UIActivityIndicatorView!


override func viewDidLoad() {
        super.viewDidLoad()

        self.setupAdRewardBanner()
    }

func setupAdRewardBanner() {

        AdColony.configureWithAppID(Constants.adColonyAppID, zoneIDs: [Constants.adColonyZoneID], options: nil,
            completion: {(zones) in

            let zone = zones.first
                zone?.setReward({ (success, name, amount) in
                if (success) {
                    let storage = NSUserDefaults.standardUserDefaults()
                    let wrappedBalance = storage.objectForKey(Constants.currencyBalance)
                    var balance = 0
                    if let nonNilNumWrappedBalance = wrappedBalance as? NSNumber {
                        balance = Int(nonNilNumWrappedBalance.integerValue)
                    }
                    balance = balance + Int(amount)

                    let newBalance: NSNumber = NSNumber(integerLiteral: balance)
                    storage.setValue(newBalance, forKey: Constants.currencyBalance)
                    storage.synchronize()

                    self.updateCurrencyBalance()
                }


            })


           //If the application has been inactive for a while, our ad might have expired so let's add a check for a nil ad object
                NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(GameViewController.onBecameActive), name: "onBecameActive", object: nil)

                //AdColony has finished configuring, so let's request an interstitial ad
                self.requestInterstitial()

        })

        NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(GameViewController.triggerAdReward), name: "triggerAdReward", object: nil)

        self.updateCurrencyBalance()
    }


    func requestInterstitial()
    {
        //Request an interstitial ad from AdColony
        AdColony.requestInterstitialInZone(Constants.adColonyZoneID, options:nil,

                                     //Handler for successful ad requests
            success:{(newAd) in

                //Once the ad has finished, set the loading state and request a new interstitial
                newAd.setClose({

                    self.requestInterstitial()
                })

                //Interstitials can expire, so we need to handle that event also
                newAd.setExpire( {
                    self.ad = nil


                    self.requestInterstitial()
                })

                //Store a reference to the returned interstitial object
                self.ad = newAd


            },

            //Handler for failed ad requests
            failure:{(error) in
                NSLog("SAMPLE_APP: Request failed with error: " + error.localizedDescription + " and suggestion: " + error.localizedRecoverySuggestion!)
            }
        )
    }

    func triggerAdReward(sender: AnyObject)
    {
        if let ad = self.ad {
            if (!ad!.expired) {
                ad?.showWithPresentingViewController(self)
            }
        }
    }


    func updateCurrencyBalance()
    {
        //Get currency balance from persistent storage and display it
        let storage = NSUserDefaults.standardUserDefaults()
        let wrappedBalance = storage.objectForKey(Constants.currencyBalance)
        var balance: Int = 0
        if let nonNilNumWrappedBalance = wrappedBalance as? NSNumber {
            balance = Int(nonNilNumWrappedBalance.integerValue)
        }

        print("current balance ", balance)
        //XXX Run animation of giving user coins and update view
    }

    func onBecameActive()
    {
        //If our ad has expired, request a new interstitial
        if (self.ad == nil) {
            self.requestInterstitial()
        }
    }

然后,在用户迷失GameScene后,按下按钮时,我会调用此通知以请求广告非页内广告.

And then after all that, I call this notification to request the ad interstitial when pressing a button after the user loses in GameScene.

NSNotificationCenter.defaultCenter().postNotificationName("triggerAdReward", object: nil)

我尝试调试,但似乎看不到代码进入if (success)块中.因此,那里可能存在问题.

I tried debugging, I can't seem to see the code getting inside the if (success) block. So there might be an issue there.

有人知道我在做什么吗?

Does anyone know what I'm doing wrong?

更多调试后,我注意到它没有采用这种方法

After debugging more, i noticed that it's not advancing with this method

self.requestInterstitial()

所以我的帐户可能有问题吗?为什么不通过成功而通过错误块呢?

So there might be an issue with my account maybe? Why is not passing through the success and goes through the error block?

控制台中的错误是:

SAMPLE_APP:请求失败,并出现以下错误:广告请求没有填充,并且 建议:请确保您已在 控制面板: http://clients.adcolony.com .

SAMPLE_APP: Request failed with error: No fill for ad request and suggestion: Make sure you have configured your zone properly in the control panel: http://clients.adcolony.com.

谢谢.

推荐答案

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆