这是我的代码。奇怪的是我可以看到完整的广告,但它没有在模拟器或真实设备中显示横幅,我也看不到任何错误日志。我刚刚显示了AdMob版本的日志。我不知道这里发生了什么。如果我的代码有任何问题,请帮助我。
Google移动广告SDK版:afma-sdk-i-v7.7.0
import UIKit
import GoogleMobileAds
class ViewController: UIViewController, GADBannerViewDelegate {
var bannerView:GADBannerView?
override func viewDidLoad() {
super.viewDidLoad()
bannerView = GADBannerView(adSize: kGADAdSizeBanner)
bannerView?.adUnitID = "ca-app-pub-0074244033587929/9554929828"
bannerView?.delegate = self
bannerView?.rootViewController = self
self.view.addSubview(bannerView!)
let request:GADRequest = GADRequest()
request.testDevices = ["65e9360edef670258b91c55321caed08"]
bannerView?.loadRequest(request)
print("Google Mobile Ads SDK version: " + GADRequest.sdkVersion())
}
//GADBannerViewDelegate
func adViewDidReceiveAd(view: GADBannerView!) {
print("adViewDidReceiveAd:\(view)");
bannerView?.hidden = true
}
func adView(view: GADBannerView!, didFailToReceiveAdWithError error: GADRequestError!) {
print("\(view) error:\(error)")
bannerView?.hidden = false
}
func adViewWillPresentScreen(adView: GADBannerView!) {
print("adViewWillPresentScreen:\(adView)")
bannerView?.hidden = false
}
func adViewWillLeaveApplication(adView: GADBannerView!) {
print("adViewWillLeaveApplication:\(adView)")
bannerView?.hidden = false
}
func adViewWillDismissScreen(adView: GADBannerView!) {
print("adViewWillDismissScreen:\(adView)")
bannerView?.hidden = false
}
}
答案 0 :(得分:0)
您是否添加了此处提到的所有框架。 Please cross check
答案 1 :(得分:0)
尝试以下步骤:
GoogleMobileAds
sdk。GADBannerView
导入UIKit
导入GoogleMobileAds
class ViewController: UIViewController {
@IBOutlet weak var viewBanner: GADBannerView!
override func viewDidLoad() {
super.viewDidLoad()
//Advertisement
viewBanner.adUnitID = "ca-app-pub-3940256099942544/2934735716"
viewBanner.rootViewController = self
viewBanner.loadRequest(GADRequest())
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}