[英]Admob interstitial ad delegate
我正在嘗試將代理人分配到admob插頁式廣告,以便我可以處理廣告事件。
GADInterstitialDelegate實現類:
class AdDelegate: NSObject, GADInterstitialDelegate
{
//Interstitial delegate
func interstitial(ad: GADInterstitial!, didFailToReceiveAdWithError error: GADRequestError!) {
println("interstitialDidFailToReceiveAdWithError:\(error.localizedDescription)")
}
func interstitialDidReceiveAd(ad: GADInterstitial!) {
println("interstitialDidReceiveAd")
}
func interstitialWillDismissScreen(ad: GADInterstitial!) {
println("interstitialWillDismissScreen")
}
func interstitialDidDismissScreen(ad: GADInterstitial!) {
println("interstitialDidDismissScreen")
}
func interstitialWillLeaveApplication(ad: GADInterstitial!) {
println("interstitialWillLeaveApplication")
}
func interstitialWillPresentScreen(ad: GADInterstitial!) {
println("interstitialWillPresentScreen")
}
}
將代理人分配給廣告:
add.delegate = AdDelegate()
問題是AdDelegate實施類中沒有觸發廣告事件(廣告顯示正確)任何想法為什么?
我不能在與分配給廣告對象相同的類中實現GADInterstitialDelegate,因為廣告對象是在類func中創建的,這會給編譯器錯誤
GADInterstitial委托是一個弱存儲屬性,因此您應該在類中創建一個存儲屬性:
var adDelegate : AdDelegate? // to store the delegate
func createInterstitial()->GADInterstitial {
var interstitial = GADInterstitial()
interstitial.adUnitID = "ca-app-pub-6938332798224330/6206234808";
adDelegate = AdDelegate()
interstitial.delegate = adDelegate //delegate is weak so we need to store the property
return interstitial
}
請查看文檔以更好地了解ARC的工作原理https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/AutomaticReferenceCounting.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.