gpt4 book ai didi

Swift - ADBannerView

转载 作者:搜寻专家 更新时间:2023-10-30 22:22:04 28 4
gpt4 key购买 nike

我尝试用像 Objective C 这样的旧方法来实现 ADBannerView 但没有成功。一切正常,但广告没有出现,它仍然是一个空白字段。

func bannerViewDidLoadAd(banner: ADBannerView!) {
UIView.beginAnimations(nil, context: nil)
UIView.setAnimationDuration(1)
banner.alpha = 1
UIView.commitAnimations()
}

func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
UIView.beginAnimations(nil, context: nil)
UIView.setAnimationDuration(1)
banner.alpha = 0
UIView.commitAnimations()
}

有人已经在 Swift 上试用过 iAd 吗?

最佳答案

我找到了解决方案,如何实现它。 (您也可以在每个方法中使用“banner.alpha 1.0”或其他东西。)

//import ... your normal imports as UIKit etc.
import iAd

class YourClassViewController: UIViewController, ADBannerViewDelegate {

@IBOutlet var adBannerView: ADBannerView //connect in IB connection inspector with your ADBannerView

override func viewDidLoad() {
super.viewDidLoad()

self.canDisplayBannerAds = true
self.adBannerView.delegate = self
self.adBannerView.hidden = true //hide until ad loaded
}

func bannerViewWillLoadAd(banner: ADBannerView!) {
NSLog("bannerViewWillLoadAd")
}

func bannerViewDidLoadAd(banner: ADBannerView!) {
NSLog("bannerViewDidLoadAd")
self.adBannerView.hidden = false //now show banner as ad is loaded
}

func bannerViewActionDidFinish(banner: ADBannerView!) {
NSLog("bannerViewDidLoadAd")

//optional resume paused game code

}

func bannerViewActionShouldBegin(banner: ADBannerView!, willLeaveApplication willLeave: Bool) -> Bool {
NSLog("bannerViewActionShouldBegin")

//optional pause game code

return true
}

func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
NSLog("bannerView")
}

//... your class implementation code

}

See the following answer, on how to do it without IBBuilder!

关于Swift - ADBannerView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24695302/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com