我在AdMob遇到了一个非常奇怪的问题。在我的主项目中,我收到错误消息,指出没有要加载的广告(尝试抓取GADInterstitial
时)。
但是,当我创建一个新项目时,复制了与AdMob相关的资源,启动了加载广告的项目,没有任何问题(看起来它总是加载测试广告;我只是为了确定而尝试了几次)。 / p>
在这两个项目中,我使用相同的Google广告连播:
pod 'Google-Mobile-Ads-SDK'
pod 'Google/Analytics'
我一直在尝试各种解决方案,生成不同的广告单元ID,在没有分析的情况下测试新项目,然后附加分析。它在每一步都像是一种魅力。
在我的主要项目中,我获得了一次广告,奇怪的是广告单元ID(横幅视图)。可悲的是从那以后我无法获得横幅广告或插页式广告(我之前无法检索插页式广告)。
我的目标平台是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)")
}
}
答案 0 :(得分:0)
我的问题原因是自定义User-Agent
。
希望节省一些时间的调试,因为AdMob文档没有涵盖这一点。