How to put AdMob Banner in SpriteKit?

百般思念 提交于 2020-01-14 03:44:05

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!