【发布时间】:2018-12-10 09:30:45
【问题描述】:
我想弄清楚,在每 x 次 viewdidload 调用时显示一个插页式广告。 当我的 viewdidload 调用时,我正在加载该广告。但是我想加载它,当viewdidload调用x的时候。 任何帮助将不胜感激。这是我的代码;
class DetailController: UIViewController, GADInterstitialDelegate {
//Admob
...
...
var fullScreenAds : GADInterstitial!
//Interstitial-Ad
func createAndLoadInterstitial() -> GADInterstitial? {
fullScreenAds = GADInterstitial(adUnitID: myInterstitialID)
guard let fullScreenAds = fullScreenAds else {
return nil
}
let request = GADRequest()
request.testDevices = [ kGADSimulatorID ]
fullScreenAds.load(request)
fullScreenAds.delegate = self
return fullScreenAds
}
func interstitialDidReceiveAd(_ ad: GADInterstitial) {
print("Ads loaded.")
ad.present(fromRootViewController: self)
}
func interstitialDidFail(toPresentScreen ad: GADInterstitial) {
print("Ads not loaded.")
}
//MARK: View functions
override func viewDidLoad() {
super.viewDidLoad()
......
SVProgressHUD.show()
imageView.af_setImage(withURL: URL(string: pic.largeImageURL!)!, placeholderImage: imgPlaceHolder, filter: nil, progress: nil, progressQueue: DispatchQueue.main, imageTransition: .crossDissolve(0.2), runImageTransitionIfCached: true) { (data) in
SVProgressHUD.dismiss()
}
scrollView.delegate = self
setupScrollView()
setupGestureRecognizers()
setupBanner()
self.fullScreenAds = createAndLoadInterstitial()
}
}
【问题讨论】:
-
您可以使用 UserDefaults 存储一个计数,然后检查它是否已达到限制,展示您的广告并重置计数
-
@sashatheitguy 你的意思是“每次 X 视图控制器加载后”吗?
-
@LadumorDineshkumar 是的。
-
我之前没有使用过 UserDefaults。如果有例子。它会帮助我.. @Scriptable
-
@sashatheitguy 检查我的答案。
标签: ios swift uiviewcontroller admob uikit