Getting problems when I try to implement iAd banners. Not sure quite what I'm missing. My main storyboard is setup for scenekit display. I'm trying to display an advert on the screen at the same time. Im manually creating and adding the view in the setupAds func as shown below. I've also added the delegate routines below that, and they are triggering, but I'm not seeing the ads display.
let adBannerView = ADBannerView(frame: CGRect.zeroRect)
override func viewDidLoad() {
super.viewDidLoad()
/* My other setup code here */
setupAds()
}
func setupAds() {
adBannerView.center = CGPoint(x: adBannerView.center.x, y: view.bounds.size.height - adBannerView.frame.size.height / 2)
adBannerView.delegate = self
adBannerView.hidden = true
view.addSubview(adBannerView)
}
/* My funcs to handle the splash screen and game */
// iAd delegates
func bannerViewWillLoadAd(banner: ADBannerView!) {
println("bannerViewWillLoadAd")
}
func bannerViewDidLoadAd(banner: ADBannerView!) {
self.adBannerView.alpha = 1.0
println("bannerViewDidLoadAd")
}
func bannerViewActionDidFinish(banner: ADBannerView!) {
println("bannerViewActionDidFinish")
}
func bannerViewActionShouldBegin(banner: ADBannerView!, willLeaveApplication willLeave: Bool) -> Bool {
println("bannerViewActionShouldBegin")
return true
}
func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
println("bannerViewError")
println(error)
}
The output that I get is as follows.
bannerViewWillLoadAd
bannerViewDidLoadAd
bannerViewError
Error Domain=ADErrorDomain Code=1 "Service session terminated." UserInfo=0x17466a6c0 {ADInternalErrorCode=1002, NSLocalizedDescription=Service session terminated.}
Any idea what I'm missing here?
Many thanks in advance.
Ok Indrajeet was correct. needed to be added to the super rather than self. Code now looks like:
override func viewDidLoad() {
super.viewDidLoad()
super.view.addSubview(adBannerView) // This is where I needed to add the banner.
/* Other setup stuff here */
setupAds()
}
func setupAds() {
adBannerView.center = CGPoint(x: adBannerView.center.x, y: view.bounds.size.height - adBannerView.frame.size.height / 2)
adBannerView.center = CGPoint(x: view.bounds.size.width / 2, y: view.bounds.size.height - adBannerView.frame.size.height / 2)
adBannerView.delegate = self
adBannerView.hidden = true
}
// iAd delegates
func bannerViewWillLoadAd(banner: ADBannerView!) {
println("bannerViewWillLoadAd")
}
func bannerViewDidLoadAd(banner: ADBannerView!) {
banner.hidden = false
println("bannerViewDidLoadAd")
}
func bannerViewActionDidFinish(banner: ADBannerView!) {
println("bannerViewActionDidFinish")
}
func bannerViewActionShouldBegin(banner: ADBannerView!, willLeaveApplication willLeave: Bool) -> Bool {
println("bannerViewActionShouldBegin")
return true
}
func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
println("bannerViewError")
println(error)
}
This has basically allowed me to add a standard iAd view on top of a scenekit display. Today advertising - tomorrow, the World!