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

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

问题描述

我正在SpriteKit中创建游戏,但我不知道如何在SpriteKit中使用AdMob标语。我知道如何与Swift一起使用,将视图拖到情节提要板上,依此类推...但是,有人可以帮我在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.

要在此设备上获取测试广告,请致电:request.testDevices = @ [* !** ******']; **

To get test ads on this device, call: request.testDevices = @[ *!********'" ];**

推荐答案

一切与完全相同UIKit ,除了必须以编程方式放置它外,还请确保该代码位于 GameViewController < viewDidLoad 中/ code>。只需在以下行中添加此行:

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天全站免登陆