错误和问题:
警告:当前存在 10 多个 ADBannerView 或 ADInterstitialView 实例。这是对iAd API的滥用,广告性能将因此受到影响。此消息仅打印一次。
我对广告视图的实现:
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
}
还有一件事,它说它只会显示一次,但每次我在手机上运行该应用程序时都会收到错误
经过一番搜索,我得出了这个解决方案:
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",这暂时解决了问题