我在所有viewcontroller
页面上都有此代码,可以跨多个页面控制我的AdBanner
。它在我的应用程序的最后一个版本上正常工作,但由于某些原因,我正在努力,我不认为我的应用程序正在调用bannerViewDidLoadAd
或didFailToReceiveAdWithError
函数。此外,当我更改页面时,我收到此错误。 `
“警告:ADBannerView或ADInterstitialView的实例超过10个 目前存在。这是对iAd API和广告效果的误用 结果会受到影响。此消息仅打印一次。“
`我有什么遗失的东西吗?感谢
// Ad controller
var UIiAd: ADBannerView = ADBannerView()
var screenHeight = UIScreen.mainScreen().bounds.height
var adBannerHeight: CGFloat = 50
@IBOutlet var constOne: NSLayoutConstraint!
func appdelegate() -> AppDelegate {
return UIApplication.sharedApplication().delegate as! AppDelegate
}
override func viewWillDisappear(animated: Bool) {
UIiAd.delegate = nil
UIiAd.removeFromSuperview()
}
func bannerViewDidLoadAd(banner: ADBannerView!) {
UIView.beginAnimations(nil, context: nil)
UIView.setAnimationDuration(1)
UIiAd.alpha = 1
adBannerHeight = 50
UIView.commitAnimations()
constOne.constant = 58
print("ad loaded")
}
func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
UIView.beginAnimations(nil, context: nil)
UIView.setAnimationDuration(1)
UIiAd.alpha = 0
adBannerHeight = 0
UIView.commitAnimations()
constOne.constant = 8
print("error")
}
override func viewWillAppear(animated: Bool) {
UIiAd.delegate = self
UIiAd = self.appdelegate().UIiAd
UIiAd.frame = CGRectMake(0, screenHeight - adBannerHeight , 0, 0)
self.view.addSubview(UIiAd)
}
// End of Ad Controller
答案 0 :(得分:0)
尝试更改此代码:
override func viewWillDisappear(animated: Bool) {
UIiAd.delegate = nil
UIiAd.removeFromSuperview()
}
要:
override func viewWillDisappear(animated: Bool) {
UIiAd.removeFromSuperview()
UIiAd.delegate = nil
}