I have a problem with interstitial ads from Apple. I'm doing my first app in swift, which I want to put on App store, as soon as it will be possible. But when I rewrite code for interstitial ads from obejctive-c to swift, I am able to show up the ad, but i does not have X close buuton, so I can not close it. I have not found anywher, taht I should place this button on my own, it should be there by default. I am using this functions: (I also have to say, that I'm using sprite kit, so my view controller automaticaly redirects game to Gamescene)
func showFullScreenAd() {
if requestingAd == false {
interstitial = ADInterstitialAd()
interstitial!.delegate = self
requestingAd = true
}
}
func interstitialAd(interstitialAd: ADInterstitialAd!, didFailWithError error: NSError!) {
self.interstitial = nil
requestingAd = false
}
func interstitialAdDidLoad(interstitialAd: ADInterstitialAd!) {
if interstitialAd != nil && self.interstitial != nil && self.requestingAd == true {
interstitial!.presentInView(self.view)
}
}
func interstitialAdDidUnload(interstitialAd: ADInterstitialAd!) {
interstitial = nil
requestingAd = false
}
func interstitialAdActionDidFinish(interstitialAd: ADInterstitialAd!) {
interstitial = nil
requestingAd = false
}
Thank you for help (here is a picture: http://imgur.com/jKTWRiG)
-----UPDATE----- This is solution, which just works. I make UIView, in which I present ad and close button (some cross image on background). This may not be the best solution, but app store accepted that, soooo :D
All these funcs are placed in GameViewController.swift (you can't simply control view controller from spritekit scene, you could through singleton of gameviewcontroller, it is up to you)
func showFullScreenAd() {
if requestingAd == false {
interstitial = ADInterstitialAd()
interstitial!.delegate = self
requestingAd = true
}
}
func interstitialAd(interstitialAd: ADInterstitialAd!, didFailWithError error: NSError!) {
self.interstitial = nil
requestingAd = false
}
func interstitialAdDidLoad(interstitialAd: ADInterstitialAd!) {
if interstitialAd != nil && _interstitial != nil && requestingAd == true {
self._adView = UIView()
self._adView!.frame = self.view.bounds
self.view.addSubview(_adView!)
self.button = UIButton(frame: CGRect(x: 10, y: 10, width: 40, height: 40))
self.button!.setBackgroundImage(UIImage(named: "close_button"), forState: UIControlState.Normal)
self.button!.addTarget(self, action: Selector("close"), forControlEvents: UIControlEvents.TouchDown)
self.view.addSubview(button!)
_interstitial!.presentInView(self._adView)
requestingAd = false
}
UIViewController.prepareInterstitialAds()
}
func close() {
self._adView!.removeFromSuperview()
self.button!.removeFromSuperview()
self._interstitial = nil
}
func interstitialAdDidUnload(interstitialAd: ADInterstitialAd!) {
interstitial = nil
requestingAd = false
self._adView!.removeFromSuperview()
self.button!.removeFromSuperview()
}
func interstitialAdActionDidFinish(interstitialAd: ADInterstitialAd!) {
interstitial = nil
requestingAd = false
self._adView!.removeFromSuperview()
self.button!.removeFromSuperview()
}