I am making a status app using WordPress with Xcode and Swift. I want to show AdMob's Interstitial ad when user clicks on WhatsApp button. The problem is that the ad is showing but it shows when WhatsApp is already opened by clicking on button. The ad is not shown to user and it is violating the policy of Google. How can I do something like this when the user clicks on WhatsApp share button, then ad shows and when user dismisses the ad then WhatsApp should open?
This is how I open WhatsApp from webView:
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
if navigationAction.request.url?.scheme == "whatsapp" {
guard let wurl = navigationAction.request.url else { return }
if interstitial != nil {
interstitial.present(fromRootViewController: self)
} else {
print("Ad wasn't ready")
}
if UIApplication.shared.canOpenURL(wurl as URL) {
UIApplication.shared.open(wurl as URL)
} else {
self.showToast(message: "Whatsapp Not Installed")
}
decisionHandler(.cancel)
} else {
decisionHandler(.allow)
}
}
I tried this but don’t know how to implement my code here:
func ad(_ ad: GADFullScreenPresentingAd, didFailToPresentFullScreenContentWithError error: Error) {
}
/// Tells the delegate that the ad will present full screen content.
func adWillPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) {
print("Ad will present full screen content.")
}
/// Tells the delegate that the ad dismissed full screen content.
func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) {
}