ios10 单击 iphone 的主页按钮时 scenekit 会崩溃

ios10 scenekit will crash when I click iphone's home button

我用第三方音乐播放器在后台播放音乐,然后我 运行 Xcode8、ios10 中的这段代码。效果很好。

let sceneView = SCNView(frame: self.view.bounds)
self.view.addSubview(sceneView)

let scene = SCNScene()
sceneView.scene = scene

let cameraNode = SCNNode()
cameraNode.camera = SCNCamera()

scene.rootNode.addChildNode(cameraNode)

sceneView.allowsCameraControl = true
sceneView.showsStatistics = true

但是当我点击主页按钮时,我的应用程序会崩溃并且 我收到此错误:"Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'error 561015905'".

我不知道怎么解决。

看起来像是 SceneKit 的错误。

你可以尝试它来简单地访问scene.audioEngine 为了预热音频引擎(即使您的应用不使用音频)。

561015905 stands for the error AVAudioSessionErrorCodeCannotStartPlaying. Apple Docs gives the detail of this error as: "The app is not allowed to start recording and/or playing, usually because of a lack of audio key in its Info.plist. This could also happen if the app has this key but uses a category that can't record and/or play in the background (AVAudioSessionCategoryAmbient, AVAudioSessionCategorySoloAmbient, etc.)." I am also getting the same crash when using lock button in an app that uses SceneKit but doesn't use the audio.(From Comment of DancOfDeth here: )

它看起来像一个错误,请参阅下面的相关错误报告 link:

https://openradar.appspot.com/28455923-SceneKit/CoreAudio Crash when device is locked

我已经解决了与

完全相同的问题
try! AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryAmbient)