2016-11-01 40 views
4

我想在我的遊戲中實現獎勵插頁式廣告,但我收到了很多AdColony錯誤,例如:「沒有填充廣告請求」或我的區域ID無效。來自AdColony的AdReward無法使用Swift 2.0由於某種原因

要開始的,這將是我如何配置我的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: 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
  • 看來你的代碼應該工作。
  • 由於您要實施獎勵插頁式廣告,因此應將區域類型設置爲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

+0

感謝您的評論,雖然,是的,我想你所說的一切,雙/三,檢查一切仍然沒有奏效。我最終選擇了Chartboost ..它實現起來更容易,沒有任何問題,我想我通過遵循8個簡單的步驟,在不到15分鐘的時間內實現了它。 – msqar

+0

@msqar恭喜! – xfdai

相關問題