我和AdMob遇到了一个非常奇怪的问题 . 在我的主项目中,我收到错误,即没有要加载的广告(当尝试获取 GADInterstitial
时) .
但是,当我创建一个新项目时,复制了AdMob相关的源代码,启动了加载广告的项目,没有任何问题(看起来它总是加载测试广告;我只是为了确定而尝试了几次) .
在这两个项目中,我使用相同的Google pod:
pod 'Google-Mobile-Ads-SDK'
pod 'Google/Analytics'
我一直在尝试各种解决方案,生成不同的广告单元ID,在没有分析的情况下测试新项目,然后附加分析 . 它在每一步都像一个魅力 .
在我的主要项目中,我得到了一次广告,奇怪的是广告单元ID( Banner 视图) . 可悲的是,从那以后我无法获得 Banner 广告或插页式广告(我之前无法检索插页式广告) .
我的目标平台是iOS 8 .
来源, AdMobManager
import GoogleMobileAds
class AdMobManager {
static let sharedInstance = AdMobManager()
private(set) var interstitial: GADInterstitial!
func loadInterstitialAd(delegate: GADInterstitialDelegate) -> GADInterstitial {
interstitial = GADInterstitial(adUnitID: "same-ad-unit-id-for-both-projects")
interstitial.delegate = delegate
let request = GADRequest()
request.testDevices = [ "same-test-id-for-both-projects" ]
interstitial.loadRequest(request)
return interstitial
}
}
和 ViewController
import UIKit
import GoogleMobileAds
class ViewController: UIViewController {
private var interstitial: GADInterstitial!
override func viewDidLoad() {
interstitial = AdMobManager.sharedInstance.loadInterstitialAd(self)
}
}
extension ViewController: GADInterstitialDelegate {
func interstitialDidReceiveAd(ad: GADInterstitial!) {
if interstitial.isReady {
interstitial.presentFromRootViewController(self)
} else {
NSLog("Not ready")
}
}
func interstitial(ad: GADInterstitial!, didFailToReceiveAdWithError error: GADRequestError!) {
NSLog("Error: \(error.debugDescription)")
}
}
1 回答
我的问题的原因是自定义
User-Agent
.希望节省一些小时的调试,因为AdMob文档没有涵盖这一点 .