错误和问题:
警告:目前存在超过10个ADBannerView或ADInterstitialView实例。这是对iAd API的误用,因此广告效果会受到影响。此消息仅打印一次。
我对adView的实施:
var adView = ADBannerView()
override func viewDidLoad() {
super.viewDidLoad()
adView.frame = CGRectOffset(adView.frame, 0, self.view.bounds.height - adView.bounds.height)
adView.sizeToFit()
self.view .addSubview(adView)
adView.alpha = 0.001
adView.delegate = self
}
我在互联网上看了一眼,发现我需要实现" viewWillDisappear"我这样做了:
我的第一次尝试:
override func viewWillDisappear(animated: Bool) {
adView.removeFromSuperview()
adView.delegate = nil
}
和第二个:
override func viewWillDisappear(animated: Bool) {
for view in self.view.subviews {
view.removeFromSuperview()
}
adView.removeFromSuperview()
adView.delegate = nil
}
还有一件事,它说只会显示一次,但每次我在手机上运行应用程序时都会出现错误
答案 0 :(得分:0)
经过一番搜索,我找到了这个解决方案:
let adView = ADBannerView()
override func viewDidLoad() {
super.viewDidLoad()
adView.frame = CGRectOffset(adView.frame, 0, self.view.bounds.height - adView.bounds.height)
adView.sizeToFit()
adView.alpha = 0.001
adView.delegate = self
self.view .addSubview(adView)
self.canDisplayBannerAds = true
}
override func viewWillDisappear(animated: Bool) {
for view in self.view.subviews {
view.removeFromSuperview()
}
adView.hidden = true
adView.delegate = nil
adView.removeFromSuperview()
}
显然我错过了添加" self.canDisplayBannerAds = true"并解决了现在的问题