ios - Admob display interstitial before segue - Swift -


i have button segue's on view. when user clicks button, want display interstitial ad (if 1 loaded) , once user dismisses interstitial ad, perform segue usual. if there no interstitial ad, perform segue normal.

i have code display interstitial, when user dismisses it, takes them previous view controller. have click button again taken next view controller. tips?

// in storyboard-based application, want little preparation before navigation     override func prepareforsegue(segue: uistoryboardsegue, sender: anyobject?) {         if(interstitial.isready) {             interstitial.presentfromrootviewcontroller(self)         }     } 

enter image description here

i wanted same thing. once watch ad, want proceed regular segue. added alert callback. difference mine uitableviewcell tap. in case this:

@ibaction func buttontapped(sender: uibutton) {     self.presentviewcontroller(interstitialadalert(         { adwatched in                 if adwatched                 {                     // perform segue here                 }         }),         animated: true,         completion: nil) } 

where adwatched callback parameter , interstitialadalert(watchadcallback: (adwatched: bool) function presents alert seen below:

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 loaded.")             watchadcallback(adwatched: true)         }      let cancelaction = uialertaction(title: "cancel", style: .cancel)     { (_) in             watchadcallback(adchosen: false)     }      alert.addaction(watchadaction)     alert.addaction(cancelaction)      return alert } 

hope helps. works charm me tableview! oh, make sure create , load interstitial ad in viewwillappear.


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -