【问题标题】:AdReward from AdColony not working on Swift 2.0 for some reasonAdColony 的 AdReward 由于某种原因无法在 Swift 2.0 上运行
【发布时间】:2016-11-07 19:31:47
【问题描述】:

我想在我的游戏中实施奖励插页式广告,但我收到很多 AdColony 错误,例如:“广告请求未填充”或我的区域 ID 无效。

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

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 下载示例适用于应用程序而非游戏,因此我尝试将其翻译为游戏,虽然没有那么不同,但我当前的代码可能存在问题。 所以这就是我在 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 中失败后按下按钮时,我调用此通知来请求广告插页式广告。

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

我尝试调试,我似乎看不到代码进入 if (success) 块。所以那里可能有问题。

有谁知道我做错了什么?

经过更多调试,我注意到它并没有用这种方法推进

self.requestInterstitial()

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

控制台中的错误是:

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

提前致谢。

【问题讨论】:

    标签: ios swift adcolony


    【解决方案1】:
    • 看来您的代码应该可以工作了。
    • 由于您要实现奖励插页式广告,因此应将区域类型设置为 V4VC。

    • 如果是"Zone ID invalid, please check config error",你应该在源代码和Adcolony客户端面板页面中检查两次App id和zone id。

    • 更改区域类型后,等待一段时间(10 分钟?)进行测试,服务器应该需要时间来同步状态。

    • 如果可能,在设备而不是模拟器上进行测试。

    这里是 v4vc 的文档:https://github.com/AdColony/AdColony-iOS-SDK-3/wiki/Rewarded-Interstitial-Ads-Quick-Start-Guide

    【讨论】:

    • 感谢您的评论,是的,我尝试了您所说的一切,对所有内容进行了双重/三重检查,但仍然无法正常工作。我最终选择了 Chartboost。它更容易实现,没有问题,我想我通过 8 个简单的步骤在不到 15 分钟的时间内实现了它。
    • @msqar 恭喜!
    猜你喜欢
    • 1970-01-01
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-10
    • 1970-01-01
    相关资源
    最近更新 更多