如何在Swift中实现插页式iAd(Xcode 6.1) [英] How to implement Interstitial iAds in Swift(Xcode 6.1)
问题描述
我正在尝试弄清楚如何从我的横幅视图iAds切换到插页式iAds,以释放标签式控制器的空间。出于某种原因,我完全无法找到任何资源,甚至无法使用swift开始使用这些广告。
I am trying to figure out how to switch over from my banner view iAds to interstitial iAds in order to free up space for a tabbed controller. For some reason I am completely unable to find any resource for even getting started on these ads with swift.
任何人都可以通过Swift向我提供有关插页式广告的一些信息以及如何我可以在一个项目中实现它们。
Could anyone please give me some information on interstitial iAds with Swift and how I can implement them in a project.
推荐答案
以这种方式实现非页内广告是一种相对简洁且易于理解的方式不需要使用 NSNotificationCentre
Here is a relatively cleaner and easier to follow way to implement Interstitial Ads since this way doesn't require the use of NSNotificationCentre
import UIKit
import iAd
class ViewController: UIViewController, ADInterstitialAdDelegate {
var interstitialAd:ADInterstitialAd!
var interstitialAdView: UIView = UIView()
override func viewDidLoad() {
super.viewDidLoad()
loadInterstitialAd()
}
func loadInterstitialAd() {
interstitialAd = ADInterstitialAd()
interstitialAd.delegate = self
}
func interstitialAdWillLoad(interstitialAd: ADInterstitialAd!) {
}
func interstitialAdDidLoad(interstitialAd: ADInterstitialAd!) {
interstitialAdView = UIView()
interstitialAdView.frame = self.view.bounds
view.addSubview(interstitialAdView)
interstitialAd.presentInView(interstitialAdView)
UIViewController.prepareInterstitialAds()
}
func interstitialAdActionDidFinish(interstitialAd: ADInterstitialAd!) {
interstitialAdView.removeFromSuperview()
}
func interstitialAdActionShouldBegin(interstitialAd: ADInterstitialAd!, willLeaveApplication willLeave: Bool) -> Bool {
return true
}
func interstitialAd(interstitialAd: ADInterstitialAd!, didFailWithError error: NSError!) {
}
func interstitialAdDidUnload(interstitialAd: ADInterstitialAd!) {
interstitialAdView.removeFromSuperview()
}
如果您在每个函数中添加 println(函数名称)
,只是为了跟踪您的非页内广告流程,这可能会有所帮助。如果您有任何问题或改进此代码块的方法,请发表评论。谢谢
And it may help if you put println("Function Name")
in each function just to keep track of your Interstitial Ads process. If you have any questions and or a way to improve this block of code please leave a comment. Thank You
这篇关于如何在Swift中实现插页式iAd(Xcode 6.1)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!