2016-07-26 8 views
2

私はこの問題に対処しようとしていましたが、それを修正する方法を理解できません。Segueの前にAdmobインタースティシャルを追加するにはどうすればよいですか?

現在Admobをプロジェクトに追加してインタースティシャル広告を表示していますが、インタースティシャルを終了すると以前のVC(インタースティシャルインスタンスが作成されている)に戻ります。

以下に示すように、それらをTabbar関数に追加しようとしています。しかし、segueは決して起こらず、アラートはインタースティシャルの前に表示されません。私は広告を表示してから、VCにセグをしたいと思っていました。インタースティシャルを確認する前に、ユーザーにアラートを確認して[OK]を押してもらいたいです。

何か助けが素晴らしいだろう!

//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のデリゲートを設定し、広告が却下された後セグエ。

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

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

広告イベントの完全なリストについては、GADInterstitialDelegate implementationを参照してください。

+0

恐ろしいダニエル!しかし、私はどのように私のタブバー機能でその機能を使用することができますか? – brkr

+0

@brkrグローバル変数を使用してitem.tagの値を格納し、正しいView Controllerを表示するために前述したデリゲートメソッドでswitch文を使用します。 –

関連する問題