I USE THIS JOIN iAd Banner in subview
var vc = self.view? .window? .rootViewController VK? .view.addSubview (AdView!)
When I want to hide it when in the game (because iAd reduces FPS), I call
AdView! .RemoveFromSuperview ()
When the user has finished the game, just add
var vc = self.view?.window?.rootViewController vc?.view.addSubview(adView!)
to show iAd banner again
BUT YOU NEED TO USE THIS CODE IN GameViewController
class GameViewController: ADBannerViewDelegate (you also needed to) also remember to import the iAd at the top of the game controller also import the iAd infrastructure into the project
override func viewDidLoad() { self.ShowAd()
// This one also has doLoad
func ShowAd() { super.viewDidLoad() adView = ADBannerView(adType: ADAdType.Banner) adView!.delegate = self } func bannerViewDidLoadAd(banner: ADBannerView!) { self.view.addSubview(adView!) self.view.layoutIfNeeded() println("Pass") } func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) { adView!.removeFromSuperview() /*var alert = UIAlertController(title: "iAd Message", message: "iAd Fail To Load", preferredStyle: UIAlertControllerStyle.Alert) self.presentViewController(alert, animated: false, completion: nil) alert.addAction(UIAlertAction(title: "dismiss", style: UIAlertActionStyle.Default, handler: nil)) self.view.layoutIfNeeded()*/ println("fail") }
source share