【发布时间】:2018-04-25 08:43:37
【问题描述】:
我想在我的应用中显示 AdMob 插页式广告。我设法展示测试广告。据我了解显示测试广告您应该添加测试设备,所以这就是我所做的。但是,当我删除测试设备时,我没有收到真正的广告。我想以某种方式测试是否会显示真实的广告。当我删除测试设备时,我调用了interstitial(_ ad: GADInterstitial, didFailToReceiveAdWithError error: GADRequestError) 委托方法,错误是:Request Error: No ad to show. 这是我根据指令here 编写的代码:
class MoviesViewController: UIViewController {
var interstitial: GADInterstitial!
override func viewDidLoad() {
super.viewDidLoad()
interstitial = createAndLoadInterstitial()
}
func createAndLoadInterstitial() -> GADInterstitial {
let interstitial = GADInterstitial(adUnitID: "<Ad-Unit-ID>")
interstitial.delegate = self
let request = GADRequest()
//request.testDevices = ["<Device-Test-ID>"]
interstitial.load(request)
return interstitial
}
@IBAction func didTapStartOver(_ sender: Any) {
if interstitial.isReady {
interstitial.present(fromRootViewController: self)
} else {
print("Ad wasn't ready")
interstitial = createAndLoadInterstitial()
}
}
GADInterstitialDelegate:
extension MoviesViewController : GADInterstitialDelegate {
/// Tells the delegate an ad request succeeded.
func interstitialDidReceiveAd(_ ad: GADInterstitial) {
print("interstitialDidReceiveAd")
}
/// Tells the delegate an ad request failed.
func interstitial(_ ad: GADInterstitial, didFailToReceiveAdWithError error: GADRequestError) {
print("interstitial:didFailToReceiveAdWithError: \(error.localizedDescription)")
}
/// Tells the delegate that an interstitial will be presented.
func interstitialWillPresentScreen(_ ad: GADInterstitial) {
print("interstitialWillPresentScreen")
}
/// Tells the delegate the interstitial is to be animated off the screen.
func interstitialWillDismissScreen(_ ad: GADInterstitial) {
dismiss(animated: false, completion: nil)
print("interstitialWillDismissScreen")
}
func interstitialDidDismissScreen(_ ad: GADInterstitial) {
print("interstitialDidDismissScreen")
interstitial = createAndLoadInterstitial()
}
/// Tells the delegate that a user click will open another app
/// (such as the App Store), backgrounding the current app.
func interstitialWillLeaveApplication(_ ad: GADInterstitial) {
print("interstitialWillLeaveApplication")
}
}
我添加了一个中介组,并且能够收到一个真实的广告。之后问题仍然存在(不再显示广告)。 将用于测试的设备从 iPad 更改为 iPhone 似乎也有帮助 - 这个问题似乎只能在 iPad 上重现。
【问题讨论】:
标签: ios admob interstitial