2016-07-26 50 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語句來呈現正確的視圖控制器。 –

相關問題