简体   繁体   中英

Adding AdBannerView into SpriteKit

I am currently using SpriteKit and am trying to incorporate iAd into it. From what I have seen, it seems like the best thing to do is to put it in a subclass of UIViewController since you can't add AdBannerView to an Sk Scene. However, I can't figure out how to add the UIViewContoller class to my SKScene.

My Ads class of UIViewController contains:

iAdSupported = iAdTimeZoneSupported()

bannerDisplayed = false

   if iAdSupported {

        iAdView = ADBannerView(adType: ADAdType.Banner)

        iAdView?.frame = CGRectMake(0, 0 - iAdView!.frame.height, iAdView!.frame.width, iAdView!.frame.height)

        iAdView?.delegate = self

        self.view.addSubview(iAdView!)

}

The class goes through and debugs like it has added to the view but is not visible on top of the SKScene. To call the Ads Class I call:

var AdsController: Ads!
AdsController = Ads()
AdsController.setupAds()

I have also tried the following in the SKScene:

var currentViewController:UIViewController=UIApplication.sharedApplication().keyWindow.rootViewController!
currentViewController.presentViewController(Ads, animated: true, completion: nil)`

I have looked at a ton of pages on this and can't seem to find anything in swift that solves this problem.

Any help would be great, Thanks so much!

Nick

Try use this class https://github.com/sunkanmi-akintoye/iOS-Ads-Admob-and-iAd really easy to implement. Add this line in ViewController :

override func viewDidLoad() {
    super.viewDidLoad()
     Ads.sharedInstance.presentingViewController = self
   ...

}

and this for show AdBannerView :

Ads.sharedInstance.showInterAd()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM