Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMark Cranston
1,817 PointsError with Iad
I am using the Sprite Kit Game template and am trying to implant iAd using Jared Davidson tutorial (https://www.youtube.com/watch?v=nba7lzCL5uI). When I run the app I get this bug error: https://drive.google.com/file/d/0B_MhAY9IEatJaC1hVTlwR1JnTVU/view?usp=sharing
Do you have any Idea why this is happening? is there a conflict between iAd an Sprite Kit? Thanks in advance!
Here is some of my code from the viewController.swift. I did not include all of it, but the part I did not include just controls button and other function stuff, that I do no think is relevant to this bug.
import UIKit
import SpriteKit
import iAd
extension SKNode {
class func unarchiveFromFile(file : String) -> SKNode? {
if let path = NSBundle.mainBundle().pathForResource(file, ofType: "sks") {
var sceneData = NSData(contentsOfFile: path, options: .DataReadingMappedIfSafe, error: nil)!
var archiver = NSKeyedUnarchiver(forReadingWithData: sceneData)
archiver.setClass(self.classForKeyedUnarchiver(), forClassName: "SKScene")
let scene = archiver.decodeObjectForKey(NSKeyedArchiveRootObjectKey) as! GameScene
archiver.finishDecoding()
return scene
} else {
return nil
}
}
}
class GameViewController: UIViewController, ADBannerViewDelegate {
@IBOutlet var BottomAdBannerOutlet: ADBannerView!
// I removed the button code here
override func viewDidLoad() {
super.viewDidLoad()
BottomAdBannerOutlet.hidden = true
BottomAdBannerOutlet.delegate = self
self.canDisplayBannerAds = true
if let scene = GameScene.unarchiveFromFile("GameScene") as? GameScene {
// Configure the view.
let skView = self.view as! SKView
skView.showsFPS = true
skView.showsNodeCount = true
/* Sprite Kit applies additional optimizations to improve rendering performance */
skView.ignoresSiblingOrder = true
/* Set the scale mode to scale to fit the window */
scene.scaleMode = .AspectFill
skView.presentScene(scene)
}
}
override func shouldAutorotate() -> Bool {
return true
}
override func supportedInterfaceOrientations() -> Int {
if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
return Int(UIInterfaceOrientationMask.AllButUpsideDown.rawValue)
} else {
return Int(UIInterfaceOrientationMask.All.rawValue)
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Release any cached data, images, etc that aren't in use.
}
func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
NSLog("Ad did not load")
}
func bannerViewWillLoadAd(banner: ADBannerView!) {
}
func bannerViewActionShouldBegin(banner: ADBannerView!, willLeaveApplication willLeave: Bool) -> Bool {
return true
}
func bannerViewDidLoadAd(banner: ADBannerView!) {
BottomAdBannerOutlet.hidden = false
}
override func prefersStatusBarHidden() -> Bool {
return true
}
}
1 Answer
Greg Kaleka
39,021 PointsHi Mark,
What's the actual error message you're getting? Your screenshot is missing the most important part :).
Looks like it starts with "cannot cast..."
Mark Cranston
1,817 PointsThe error says, "Could not cast value of type 'UIView' (0x10453de88) to 'SKView' (0x1036ff716). (11db)"
Christopher Augg
21,223 PointsChristopher Augg
21,223 PointsMark,
I'm sorry, but I have not used Sprite Kit myself yet. Have you looked at stackoverflow ? Please let me know if that helps or not. I will try and find someone that can help you further.
Regards,
Chris