Reputation: 150
I can't seem to be able to load iAd banners in a Swift app within a SpriteKit game... Been googleing it for a while and nothing.... It simply won't make the network call to load the ad... I have implemented all of the necessary calls and set the delegate with no luck...
func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
println("Failed to load ad")
}
func bannerViewDidLoadAd(banner: ADBannerView!) {
println("Loaded Ad")
//now show the ad
//set position off-screen
banner.frame.origin.y = screenHeight
banner.hidden = false
}
func createAds() {
//create ad to allow it to load
let adBanner = ADBannerView(frame: CGRectMake(0, 0, screenWidth, 50))
adBanner.delegate = self
adBanner.center = CGPointMake(screenWidth/2, 25)
adBanner.hidden = true
//add to screen
self.view?.addSubview(adBanner)
println("Created Ad")
}
func hideAds() {
}
func bannerViewActionShouldBegin(banner: ADBannerView!, willLeaveApplication willLeave: Bool) -> Bool {
return true
}
then I simply call the createAds() method when the game starts which then shows a white rectangle at the top of the screen ("0,0", "quote, quote, is it zero zero a the top"?)
Upvotes: 1
Views: 301
Reputation: 88
You need to do it like this (in GameViewController.swift):
override func viewDidLoad() {
super.viewDidLoad()
self.canDisplayBannerAds = true
}
func bannerViewActionShouldBegin(banner: ADBannerView!, willLeaveApplication willLeave: Bool) -> Bool {
return true
}
func bannerViewDidLoadAd(banner: ADBannerView!) {
}
func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
NSLog("error!")
}
func bannerViewWillLoadAd(banner: ADBannerView!) {
}
You also need to import iAd
and add ADBannerViewDelegate
to the GameViewController class
Upvotes: 0