Swift and Spritekit won't run on device runnin

2020-02-09 10:45发布

问题:

I'm getting a really weird warning when I try to run my Swift project on my device, using Xcode 6.

The device is running iOS 7.1, and my mac is running Mavericks.

I have written a little game in Swift and SpriteKit, and it works in Simulator, but when I try to run it on my device, I get a warning, and my device only shows a black background.

I get the same result when trying to run a fresh SpriteKit project. But if I run a fresh Single Page Application using Swift, it runs normally.

This is the warning I get:

Any suggestions?

回答1:

I also got this crash and, comparing to the 7.1.1 SDK SpriteKit game template, it appears to be related to loading the scene from an .sks file.

I changed it to use a different initializer like this:

let scene = GameScene(size: skView.bounds.size)

After that, the template project is not crashing anymore on my iPad mini with iOS 7.1.1. However, the plane sprites don't get rendered. You can see the node count (on the bottom right corner) go up with each tap, but the sprites aren't visible. The "Hello, World!" label shows fine, though...



回答2:

Same behaviour here: default generated SpriteKit game was crashing. Now with the XCode 6 final, it all seems to work just fine, but try to add a particle emitter, and you back to XCode crashing hell. XCode keeps crashing on any particle emitter file saved as .sks file. I found that this is a known bug in XCode 6, that seems to be fixed only in 6.1 beta. See: Can't open particle SKS files



回答3:

I was getting this problem too, with me it was crashing on the self.addChild(myLabel) on the default scene that loads (the one with Chalkduster "Hello, World!" and spaceships spinning on touch, I think it's called GameScene by default).

Comment out the self.addChild(myLabel) in GameScene and see if that stops the crashes. As a temporary solution I just made the viewDidLoad method load up another scene straight away and the new scene acts as you'd expect. It seems like it's something on Apples end of things, xCode6 is only in beta after all.



回答4:

Try again with the latest Xcode 6 beta 4. There are still some bugs, but the basic SpriteKit template is now working fine.