I have an app that shows an interstitial ad after a few pages on a UIPageViewController. Usually the ad is OK, and I can dismiss it by its own 'X' button. But there are some ads (especially the ones about games like Clash of Kings, i've noticed) that will not dismiss some times regardless of how many times I hit the 'X' button.
I even have a time that dismisses modals such as the interstitial after 5 seconds, but with these particular ads, it won't work.
Here is my code:
func createAndLoadInterstitial() -> GADInterstitial {
let interst = GADInterstitial(adUnitID: "..")
interst.delegate = self
let request = GADRequest()
interst.load(request)
return interst
}
func showInterstitial() {
if interstitial.isReady {
self.interstitial.present(fromRootViewController: self)
self.timer = Timer.scheduledTimer(timeInterval: 5, target: self, selector: #selector(self.dismissInterstitial), userInfo: nil, repeats: false)
} else {
print("Ad wasn't ready")
}
}
func dismissInterstitial() {
self.dismiss(animated: true, completion: nil) //THIS WORKS FINE EXCEPT FOR THESE PARTICULAR ADS.
}
I tried making sure it was on the main thread as well with DispatchQueue.main.async but again, this doesn't work every time.
Is there a way to fix this, or something I might be missing?
Thanks.