Swift / XCode – 在dismissViewController期间AdMob插页式广告

我有一个简单的应用程序,需要一些帮助,让interstitials正确发射。 该应用程序只是两个意见。 MainVC和ModalVC。 在ModalVC上,有一个[CLOSE]button将用户返回到MainVC:

@IBAction func closeButtonPressed(sender: UIButton) { self.dismissViewControllerAnimated(true, completion: nil). } 

要从MainVC到ModalVC,我正在使用以下内容:

 self.performSegueWithIdentifier("mainSegue", sender: self) // Present Modally segue, default presentation, cross dissolve transition. 

我遇到的主要问题是触发closeButtonPressed上的插页式广告。 我希望插页式广告在后台播放,而dismissViewController会执行。 这样,一旦用户完成了插页式广告,他们将返回到MainVC。 (插页式广告会每4次转换一次,只是一个参考,对于我的主要问题来说不是非常重要。)发生的是间隙性负载,然后立即closures。 见下面的代码:

 @IBAction func closeButtonPressed(sender: UIButton) { //INTERSTITIAL TRIGGER! if (self.interstitial.isReady) { self.interstitial.presentFromRootViewController(self) self.interstitial = self.createAd() dismissViewControllerAnimated(true, completion: nil) } else { dismissViewControllerAnimated(true, completion: nil) } } 

此外,我尝试了以下GADInterstitialDelegate方法…其中偶然产生了与上面的代码相同的结果:

 @IBAction func closeButtonPressed(sender: UIButton) { //INTERSTITIAL TRIGGER! if (self.interstitial.isReady) { self.interstitial.presentFromRootViewController(self) self.interstitial = self.createAd() interstitialDidReceiveAd(interstitial) } else { dismissViewControllerAnimated(true, completion: nil) } } /// Called when an interstitial ad request succeeded. func interstitialDidReceiveAd(ad: GADInterstitial!) { print("interstitialDidReceiveAd") self.dismissViewControllerAnimated(true, completion: nil) } 

我也尝试了在[CLOSE]button上的一个Unwind segue,在MainVC上触发以下内容:

 @IBAction func unwindToMain(segue: UIStoryboardSegue) { // unwinded if (self.interstitial.isReady) { self.interstitial.presentFromRootViewController(self) self.interstitial = self.createAd() } } 

哪个给了我这个错误: 警告:试图在testAd.MainVC:0x7f9e02c44b50上呈现GADInterstitialViewController:0x7f9e01ca7a80其视图不在窗口层次结构中!

理想情况下,我希望Interstitial触发器都保留在ModalVC上,因为我希望IntersVCial在MainVC出现之前出现。

任何帮助表示赞赏。 在这一天轮了我的轮胎超过一天…啧啧…感谢提前!

终于明白了这一点。 这里的诀窍是只使用视图控制器中的button来触发插页式广告。 然后在与插页相同的视图中,使用GADInterstitialDelegate方法,具体为:interstitialWillDismissScreen

 class ModalVC: UIViewController, GADInterstitialDelegate func interstitialWillDismissScreen(ad: GADInterstitial!) { self.dismissViewControllerAnimated(true, completion: nil) } 

以下是您可以使用的所有插页式委托​​方法的完整列表: https : //firebase.google.com/docs/admob/ios/ad-events

Interesting Posts