objective c - iOS Swift: iAd Interstitial leaves black screen after dismissed -


i'm trying add ads game, every time user loses present game on view controller. on occasions, when ad loads have full screen interstitial shown on top of game on screen.

my problem interstitial doesn't come close button, added 1 user doesn't feel forced tap on ad every time comes up. when user clicks close button, ad dismissed , game on view controller once again shown. problem is, once in while (at random, maybe first time or after couple of runs through) ad dismissed , leaves black screen.

any ideas why happening? i've been scratching head few days trying figure out.

thanks!! here code:

// ad variables var interstitialadview: uiview = uiview() var interstitial:adinterstitialad! var intersitialtracker = false var closebutton:uibutton!  override func viewdidappear(animated: bool) {     if !intersitialtracker {             loadinterstitialad()     } }  // buttons restart game, , return home screen @ibaction func restartbuttonpressed(sender: anyobject) {      intersitialtracker = false     interstitial = nil     delegate?.gameoverviewcontrollerdidpressrestart(self)  }  @ibaction func homebuttonpressed(sender: anyobject) {     interstitial = nil     delegate?.gameoverviewcontrollerdidpresshomebutton(self)   }  func loadinterstitialad() {     if interstitial != nil {         interstitial.delegate = nil     }     interstitial = adinterstitialad()     interstitial.delegate = self     intersitialtracker = true }  func interstitialadwillload(interstitialad: adinterstitialad!) { }  func interstitialaddidload(interstitialad: adinterstitialad!) {     interstitialadview = uiview()     interstitialadview.frame = self.view.bounds     view.addsubview(interstitialadview)      closebutton = uibutton(frame: cgrect(x: 20, y:  20, width: 20, height:20))     closebutton.setbackgroundimage(uiimage(named: "close"), forstate: uicontrolstate.normal)       closebutton.addtarget(self, action: selector("close"), forcontrolevents: uicontrolevents.touchdown)     self.view.addsubview(closebutton)     interstitialad.presentinview(interstitialadview) }  // called when user leaves ad func interstitialadactiondidfinish(interstitialad: adinterstitialad!) {     interstitialadview.removefromsuperview()     closebutton.removefromsuperview()     interstitial = nil     closebutton = nil }  // called when user goes in ad func interstitialadactionshouldbegin(interstitialad: adinterstitialad!, willleaveapplication willleave: bool) -> bool {     return true  }  func interstitialad(interstitialad: adinterstitialad!, didfailwitherror error: nserror!) { }  func interstitialaddidunload(interstitialad: adinterstitialad!) {     interstitialadview.removefromsuperview()     closebutton.removefromsuperview()     interstitial = nil     closebutton = nil }  // close button ads func close() {     if closebutton != nil {         interstitialadview.removefromsuperview()         closebutton.removefromsuperview()         interstitial = nil         closebutton = nil     } } 

sorry lengthy post, thanks!!!!!

not entirely sure why happening 1 way work around call function shows game on screen. can't tell line of code above code have given this;

func close() { if closebutton != nil {     interstitialadview.removefromsuperview()     closebutton.removefromsuperview()     interstitial = nil     closebutton = nil     self.gameoverscreen() } 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -