如何将 AdMob 横幅放入 SpriteKit? [英] How to put AdMob Banner in SpriteKit?

查看:37
本文介绍了如何将 AdMob 横幅放入 SpriteKit?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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 = @[ *!********'" ];**

解决方案

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)

这篇关于如何将 AdMob 横幅放入 SpriteKit?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆