Hi guys,
Im struggling to get my code working, i want to add a shared iads adbanner in the appdelegate class and turn it on and off in seperate swift file scenes. Im new to this so excuse my ignorance! here is my appdelegate code:
I get the appropriate 'printed' lines but the adbanner never pops up...
i call this in my 'GameScene' file:
NSNotificationCenter.defaultCenter().postNotificationName("showiAdBanner", object: nil)
AppDelegate file: (Ignore the size of the banner... i havent worked that bit out yet!)
import UIKit
import iAd
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, ADBannerViewDelegate {
var window: UIWindow?
var bannerAd:ADBannerView = ADBannerView(frame: CGRect(x: 0, y: 0, width: 1024, height: 100))
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
/
/
NSNotificationCenter.defaultCenter().addObserver(self, selector: "showiAdBanner", name: "showiAdBanner", object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "hideiAdBanner", name: "hideiAdBanner", object: nil)
bannerAd.delegate = self
return true
}
func applicationWillResignActive(application: UIApplication) {
/
/
}
func applicationDidEnterBackground(application: UIApplication) {
/
/
}
func applicationWillEnterForeground(application: UIApplication) {
/
}
func applicationDidBecomeActive(application: UIApplication) {
/
}
func applicationWillTerminate(application: UIApplication) {
/
}
func showiAdBanner() {
/
bannerAd.hidden = false
/
print("showiadbanner")
}
func hideiAdBanner() {
bannerAd.hidden = true
print("hideiadbanner")
}
func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
bannerAd.hidden = true
print("bannerViewError")
}
func bannerViewWillLoadAd(banner: ADBannerView!) {
print("bannerViewWillLoadAd")
}
func bannerViewDidLoadAd(banner: ADBannerView!) {
print("bannerViewDidLoadAd")
bannerAd.hidden = false
}
func bannerViewActionDidFinish(banner: ADBannerView!) {
print("bannerViewActionDidFinish")
}
func bannerViewActionShouldBegin(banner: ADBannerView!, willLeaveApplication willLeave: Bool) -> Bool {
print("bannerViewActionShouldBegin")
return true
}
}