Alim2
Alim2

Reputation: 41

Admob w/Spritekit

I am trying to get a banner ad showing up on a certain scene every time a user loads it. I know I have to position it programmatically here.

So far I:

import GoogleMobileAds

and then I:

let 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.load(request)
view?.addSubview(BannerAd)

But I get the following errors:

Cannot assign value of type 'GameOverScene' to type 'UIViewController?'

and I'm putting this code inside of my init for this scene (it's a gameOver scene that I transition to when the player wins/losses).

Is there anyway to get this banner ad to show up or do I need to use UIKit here?

Upvotes: 1

Views: 186

Answers (2)

ukneeq
ukneeq

Reputation: 11

I believe you just need to add the GADBannerViewDelegate protocol to your class.

    class GameOverScene: SKScene, GADBannerViewDelegate {
       ...
    }

Upvotes: 1

Sweeper
Sweeper

Reputation: 271625

Is there anyway to get this banner ad to show up or do I need to use UIKit here?

You should use UIKit here. Go to your storyboard, add a GADBannerView to your view controller's view. Add an outlet to your ViewController.swift file. In viewDidLoad, you can then set rootViewController to self and do other configurations.

Upvotes: 0

Related Questions