I would like to realize a reward in my game, but I get a lot of AdColony errors, such as: "No fill for requesting an ad" or that my zone identifier is invalid.
For starters, this will be the way 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)
The example they give you with the SDK download is for non-games applications, so I tried to translate it for games, although that was not the case, but there might be a problem with my current code. So this is how I have it in my GameViewController.swift.
struct Constants
{
static let adColonyAppID = "app5aab6bb6aaf3xxxxxx"
static let adColonyZoneID = "vz19959f95bd62xxxxxx"
static let currencyBalance = "coinAmount"
}
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()
}
})
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(GameViewController.onBecameActive), name: "onBecameActive", object: nil)
self.requestInterstitial()
})
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(GameViewController.triggerAdReward), name: "triggerAdReward", object: nil)
self.updateCurrencyBalance()
}
func requestInterstitial()
{
AdColony.requestInterstitialInZone(Constants.adColonyZoneID, options:nil,
success:{(newAd) in
newAd.setClose({
self.requestInterstitial()
})
newAd.setExpire( {
self.ad = nil
self.requestInterstitial()
})
self.ad = newAd
},
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()
{
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)
}
func onBecameActive()
{
if (self.ad == nil) {
self.requestInterstitial()
}
}
And after all this, I call this notification to request an advertisement by clicking the button after the user loses in GameScene.
NSNotificationCenter.defaultCenter().postNotificationName("triggerAdReward", object: nil)
, , if (success). .
- , ?
, ,
self.requestInterstitial()
, ? ?
:
SAMPLE_APP: : : , : http://clients.adcolony.com.
.