【发布时间】:2018-07-23 01:35:20
【问题描述】:
我已添加代码以在我的应用程序中添加 admob。测试 adunit 在模拟器上提供测试广告,但不在真实设备上。尽管我已在测试设备中添加了我的设备 ID。 我在link 上找到了答案,但它是关于没有展示的真实广告。但就我而言,它也没有显示测试广告。 这是我正在使用的代码。
bannerView = GADBannerView(adSize: kGADAdSizeBanner)
bannerView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(bannerView)
view.addConstraints(
[NSLayoutConstraint(item: bannerView,
attribute: .bottom,
relatedBy: .equal,
toItem: bottomLayoutGuide,
attribute: .top,
multiplier: 1,
constant: 0),
NSLayoutConstraint(item: bannerView,
attribute: .centerX,
relatedBy: .equal,
toItem: view,
attribute: .centerX,
multiplier: 1,
constant: 0)
])
bannerView.adUnitID = "ca-app-pub-3940256099942544/2934735716"
bannerView.rootViewController = self
bannerView.load(GADRequest())
let requestAd:GADRequest = GADRequest()
requestAd.testDevices = [kGADSimulatorID, "b8e41041fae0a22d8d95ff6b9c0e003a"]
bannerView.load(requestAd)
【问题讨论】: