如果将出现viewcontroller,我想每次都显示一个广告横幅。我有这个代码:
import UIKit
import iAd
class LMTableViewController: UIViewController, ADBannerViewDelegate {
var adView: ADBannerView?
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func bannerViewDidLoadAd(banner: ADBannerView!) {
self.view.addSubview(adView!)
self.view.layoutIfNeeded()
}
func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
adView!.removeFromSuperview()
self.view.layoutIfNeeded()
}
override func viewWillAppear(animated: Bool) {
// iAd
self.interstitialPresentationPolicy = ADInterstitialPresentationPolicy.Manual
}
}
问题是,广告不会每次都展示。 它将随机显示。 大家能告诉我解决方案吗?
答案 0 :(得分:0)
import UIKit
import iAd
class ViewController: UIViewController, ADBannerViewDelegate {
@IBOutlet var adBannerView: ADBannerView!
override func viewDidLoad()
{
super.viewDidLoad()
self.canDisplayBannerAds = true
self.adBannerView.delegate = self
self.adBannerView.hidden = true
}
func bannerViewWillLoadAd(banner: ADBannerView!) {
}
func bannerViewDidLoadAd(banner: ADBannerView!) {
self.adBannerView.hidden = false
}
func bannerViewActionDidFinish(banner: ADBannerView!) {
}
func bannerViewActionShouldBegin(banner: ADBannerView!, willLeaveApplication willLeave: Bool) -> Bool {
return true
}
func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
}
}
将上述代码粘贴到项目中。希望这可以帮助。
祝你好运,
SUPREM