Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/120.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何检测用户何时在Swift iOS中撤销间隙广告?_Ios_Swift_Admob_Gadinterstitial - Fatal编程技术网

如何检测用户何时在Swift iOS中撤销间隙广告?

如何检测用户何时在Swift iOS中撤销间隙广告?,ios,swift,admob,gadinterstitial,Ios,Swift,Admob,Gadinterstitial,我正在使用Swift中的present在iOS应用程序中显示GADALAD。下面是我用来显示广告的代码 func showAd() { if self.interstitialAd.isReady { self.interstitialAd.present(fromRootViewController: self) } } 我在屏幕上运行一个计时器,一旦广告从屏幕上消失,我想暂停并继续。有人能告诉我如何实施这个吗?我选中了InterstitualWilldism

我正在使用Swift中的present在iOS应用程序中显示
GADALAD
。下面是我用来显示广告的代码

func showAd() {
    if self.interstitialAd.isReady {
        self.interstitialAd.present(fromRootViewController: self)
    }
}

我在屏幕上运行一个计时器,一旦广告从屏幕上消失,我想暂停并继续。有人能告诉我如何实施这个吗?我选中了
InterstitualWilldismissScreen
,但似乎为此我需要从
GadInterstitualDelegate
派生自定义类。到现在为止,我直接使用
var interstituralad:gadistitural
我想知道是否有什么方法可以检查广告在屏幕上和屏幕下的状态?

你需要在课堂上加入
GadDelegate
。没有其他方法可以检查广告是否在屏幕上

class ViewController: UIViewController, GADInterstitialDelegate {

    var interstitial: GADInterstitial!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Setup interstitial here
        // Set its delegate
        interstitial.delegate = self
    }

    func interstitialWillPresentScreen(_ ad: GADInterstitial) {
        print("Ad presented")
    }

    func interstitialDidDismissScreen(_ ad: GADInterstitial) {
        // Send another GADRequest here
        print("Ad dismissed")
    }
}

你需要让你的班级代表离开,据我所知,别无选择。你不想这么做有什么原因吗?我是在丹尼尔在下面的评论后意识到的。我想我误解了这个概念,但是在下面Daniel的示例代码之后,它变得相当容易了。感谢您的评论@AmodGokhale