我已經嘗試使用我的廣告橫幅視圖來做到這一點,并且效果很好,但我真的不知道如何為我的插頁式廣告做到這一點。
我不是那么熟練,所以請嘗試以非常簡單的方式解釋它,我的替代方案是什么。
我的橫幅廣告視圖非常簡單
if UserDefaults.standard.getActiveRemoveAdsSubscription() == true {
bannerView.isHidden = true
} else if UserDefaults.standard.getActiveRemoveAdsSubscription() == true {
bannerView.isHidden = true
} else {
bannerView.isHidden = false
}
但是,我該如何處理不是 'isHidden 成員的 InterstitalAd?
這是我的插頁式廣告代碼:
import UIKit
import GoogleMobileAds
class UITabBarViewController: UITabBarController, GADFullScreenContentDelegate {
var interstitial: GADInterstitialAd!
let request = GADRequest()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
if UserDefaults.standard.getActiveRemoveAdsSubscription() == true {
} else if UserDefaults.standard.getActiveRemoveAdsSubscription() == true {
} else {
}
_ = Timer.scheduledTimer(timeInterval: 30.0, target: self, selector: #selector(timerBlock), userInfo: nil, repeats: true)
}
@objc func timerBlock()
{
print("within the timer!")
// Active link
// GADInterstitialAd.load(withAdUnitID: "x", request: request, completionHandler: {ad, error
// Test Link
GADInterstitialAd.load(withAdUnitID: "ca-app-pub-x", request: request, completionHandler: {ad, error
in
if let error = error {
print("Failed to load the ad: \(error)")
return
}
self.interstitial = ad
self.interstitial.fullScreenContentDelegate = self
})
if interstitial != nil{
interstitial!.present(fromRootViewController: self)
}
else
{
print("Ad didn't load / Wasn't ready")
}
}
func ad(_ ad: GADFullScreenPresentingAd, didFailToPresentFullScreenContentWithError error: Error) {
print("Error: \(error.localizedDescription)")
}
func adWillPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) {
print("Success!!")
}
func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) {
print("User dismissed the ad")
}
uj5u.com熱心網友回復:
有兩種情況可以處理這個問題。
- 購買后立即洗掉
GADInterstitialAd。 - 檢查是否在應用啟動時洗掉了廣告。
在這兩種情況下,使您的插頁式廣告可以為空,例如:
private var interstitial: GADInterstitialAd?
處理第一種情況:\
if Purchase.isSuccesful == true {
interstitial = nil
}
要處理第二種情況(假設您在本地保存購買狀態):在timerBlock()函式內部,只需檢查廣告是否被洗掉并相應地加載廣告,例如:
@objc func timerBlock() {
if UserDefaults.standard.getActiveRemoveAdsSubscription() == false {
// Load Ad & show Interstitial
} else {
print("Ad Removed, not loading Interstitial.")
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/483963.html
