2016-07-26 51 views
2

我一直在试图解决这个问题很长一段时间,但无法弄清楚如何解决它。如何在Segue之前添加Admob插页式广告?

目前我已将Admob添加到我的项目中,插页式广告正在显示,但是当我退出插页式广告时,它会将我返回到我以前的VC(制作插页式广告的位置)。

正如你可以看到下面我尝试将它们添加到我的TabBar功能。但segue从未发生过,也没有在间隙之前显示警报。我想展示广告,然后继续投向VC。我希望用户看到提醒并在看到插页式广告之前按下“确定”。

任何帮助将会很棒!

//TabBar Functions 

    func tabBar(tabBar: UITabBar, didSelectItem item: UITabBarItem) { 
     if (item.tag == 1) { 

      if (self.interstitial.isReady) { 
       self.interstitial.presentFromRootViewController(self) 
      } 

      self.performSegueWithIdentifier("showStore", sender: nil) 

     } else if (item.tag == 2) { 

      let alert = UIAlertController(title: "Coming Soon!", message: "Loadout", preferredStyle: .Alert) 

      alert.addAction(UIAlertAction(title: "Got It!", style: .Default, handler: nil)) 

      if (self.interstitial.isReady) { 
       self.interstitial.presentFromRootViewController(self) 
      } 

      self.presentViewController(alert, animated: true, completion: nil) 

      return 

     } else if (item.tag == 3) { 

      let alert = UIAlertController(title: "Coming Soon!", message: "God's Tower", preferredStyle: .Alert) 

      alert.addAction(UIAlertAction(title: "Got It!", style: .Default, handler: nil)) 

      if (self.interstitial.isReady) { 
       self.interstitial.presentFromRootViewController(self) 
      } 

      self.presentViewController(alert, animated: true, completion: nil) 

      return 

     } 
    } 

回答

3

设置你的GADInterstitial的委托,然后Segue公司,一旦广告已被开除。

// Add this where you're creating your GADInterstitial 
interstitial.delegate = self 

func interstitialDidDismissScreen(ad: GADInterstitial!) { 
    // Segue to your view controller here 
} 

有关广告事件的完整列表,请参阅GADInterstitialDelegate implementation

+0

太棒了!我怎样才能在我的tabbar功能中使用该功能? – brkr

+0

@brkr使用一个全局变量来存储item.tag的值,然后在我提到的委托方法中使用switch语句来呈现正确的视图控制器。 –

相关问题