2016-04-22 12 views
0

ボタンがあり、別のビューに戻ることがあります。ユーザーがこのボタンをクリックすると、インタースティシャル広告(表示されている場合)を表示し、ユーザーがインタースティシャル広告を一旦消去した後、いつものようにセグを実行します。インタースティシャル広告がない場合は、通常通りセグを実行します。Admobはセグメントの前にインタースティシャルを表示します - Swift

私はインタースティシャルを表示するコードをいくつか持っていますが、ユーザーがそれを解除すると、以前のビューコントローラーに戻されます。次のビューコントローラに移動するには、ボタンをもう一度クリックする必要があります。任意のヒント?

// In a storyboard-based application, you will often want to do a little preparation before navigation 
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { 
     if(interstitial.isReady) { 
      interstitial.presentFromRootViewController(self) 
     } 
    } 

enter image description here

+0

これを解決しましたか?私はちょうどあなたの質問に似て何かをしようとしているが、解決策を見つけることができません。私は間もなく最初に火をつけるようには思えません。 – Joe

答えて

0

私は同じことをやってみたかったです。彼らが広告を見たら、私はそれを通常のセグを続行したい。だから私はコールバックで警告を追加しました。唯一の違いは私がUITableViewCellタップだったことです。あなたのケースではちょうどこのような何か:

@IBAction func buttonTapped(sender: UIButton) 
{ 
    self.presentViewController(interstitialAdAlert(
     { adWatched in 
       if adWatched 
       { 
        // perform segue here 
       } 
     }), 
     animated: true, 
     completion: nil) 
} 
adWatchedがコールバックパラメータで

interstitialAdAlert(watchAdCallback: (adWatched: Bool)を下に見られるようにアラートを提示機能である:

func interstitialAdAlert(watchAdCallback: (adWatched: Bool) ->()) -> UIAlertController 
{ 
    let alert = UIAlertController(title: "Watch Ad?", message: "Your message here.", preferredStyle: .Alert) 
    let watchAdAction = UIAlertAction(title: "Watch Ad", style: .Default) 
     { (_) in 
      self.interstitial.isReady ? self.interstitial.presentFromRootViewController(self) : DDLogSwift.debug("The interstitial ad couldn't be loaded.") 
      watchAdCallback(adWatched: true) 
     } 

    let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel) 
    { (_) in 
      watchAdCallback(adChosen: false) 
    } 

    alert.addAction(watchAdAction) 
    alert.addAction(cancelAction) 

    return alert 
} 

・ホープ、このことができます。私のテーブルビューで私の魅力のように動作します! また、viewWillAppearにインタースティシャル広告を作成して読み込むようにしてください。

関連する問題