2016-09-25 124 views
1

我认为我正确设置了横幅广告的代码,但是当我在模拟器或iPhone上运行应用程序时,is没有显示出来。AdMob横幅广告在运行应用程序时未显示

@IBOutlet var BannerAD: GADBannerView! 

@IBOutlet var ScoreLabel: UILabel! 

var taps = Int(){ 
    didSet { 
     if taps == 330 { 
      print("You have reaches 5 taps !!") 
     } 
    } 
} 


override func viewDidLoad() { 
    super.viewDidLoad() 
    //BannerView 
    let request = GADRequest() 
    request.testDevices = [kGADSimulatorID] 
    BannerAD.delegate = self 
    BannerAD.adUnitID = "ca-app-pub-1469592343938512/3073825187" 
    BannerAD.rootViewController = self 
    BannerAD.loadRequest(request) 
+0

您是否在故事板中正确设置它,使其正确显示(使用约束)? – Nik

+0

是的,我正确地设置它。 –

+0

你确定它的大小够大吗?有时,如果广告的尺寸太小,则不会出现 – Nik

回答

0

此行添加到您的viewDidLoad(但你让广告请求前):

BannerAd = GADBannerView(adSize: kGADAdSizeBanner) 

当你这样做,你可能需要设置广告的框架,像这样:

BannerAd.frame = CGRect(x: 0, y: 0, width: 320, height: 50) 
+0

当我粘贴第二行代码时,Xcode向我显示一个错误(参数width,height,x,y不匹配任何可用的重载) –

+0

它没有第二行工作吗?我修改了第二行 – Nik

+0

不,它不幸运行不起来。没有错误了,但它不起作用。 –

0

试图实现GADBannerViewDelegate的委托方法来检查,如果应用程序正在接收广告:

func adViewDidReceiveAd(_ bannerView: GADBannerView!) { 
    print("ad received") 
} 

func adView(_ bannerView: GADBannerView!, didFailToReceiveAdWithError error: GADRequestError!) { 
    print("fail to receive ad with error: \(error.localizedDescription)") 
}