问题
I am creating an game in SpriteKit, and I don't know how to use AdMob banner in SpriteKit. I know how to use with Swift where you drag the view to your storyboard, and etc... But once again, Can anyone help me to use it in SpriteKit?
Getting this error when applying to place banner.
To get test ads on this device, call: request.testDevices = @[ *!********'" ];**
回答1:
Everything is the exact same as with UIKit
, except that you have to position it programmatically. Also make sure that this code goes in viewDidLoad
in your GameViewController
. Just add this line in:
BannerAd.frame = CGRect(x: 0, y: 0, width: 320, height: 50)
All in all you banner ad code should look something like this:
var BannerAd = GADBannerView(adSize: kGADAdSizeBanner)
BannerAd.frame = CGRect(x: 0, y: 0, width: 320, height: 50)
BannerAD.delegate = self
BannerAD.adUnitID = "ca-app-pub-##/##"
BannerAD.rootViewController = self
let request = GADRequest()
request.testDevices = [kGADSimulatorID, "*************************"]
BannerAD.loadRequest(request)
view.addSubview(BannerAd)
来源:https://stackoverflow.com/questions/41688890/how-to-put-admob-banner-in-spritekit