AVAudioSession 未知
AVAudioSession unknown
我正在尝试在我的 Swift SpriteKit 应用程序中使用 AVAudioSession。我遇到了 "undeclared type" 个奇怪的问题。例如...
import AVFoundation
var audioSession:AVAudioSession {
return AVAudioSession.sharedInstance()
}
这 returns AVAudioSession 的第一个实例上的错误,Use of undeclared type 'AVAudioSession'
。稍后在我的代码中我有这一行...
import AVFoundation
override func didMoveToView(view: SKView) {
var titleError:NSError?
audioSession.setCategory(AVAudioSessionCategoryPlayback, error: &error)
...
returns AVAudioSessionCategoryPlayback
上同样的错误。这些东西在 Swift/Xcode 的最新版本中移动了吗?
您应该在 class
的顶部添加以下内容
import AVFoundation
并确保 AVFoundation 在您的 "Link Binary with Libraries"
中
好的,这是旧问题,我相信您现在已经解决了,但我 运行 遇到了同样的错误。问题是我正在为 Mac 构建,而 AVAudioSession(当前)仅适用于 iOS。
我正在尝试在我的 Swift SpriteKit 应用程序中使用 AVAudioSession。我遇到了 "undeclared type" 个奇怪的问题。例如...
import AVFoundation
var audioSession:AVAudioSession {
return AVAudioSession.sharedInstance()
}
这 returns AVAudioSession 的第一个实例上的错误,Use of undeclared type 'AVAudioSession'
。稍后在我的代码中我有这一行...
import AVFoundation
override func didMoveToView(view: SKView) {
var titleError:NSError?
audioSession.setCategory(AVAudioSessionCategoryPlayback, error: &error)
...
returns AVAudioSessionCategoryPlayback
上同样的错误。这些东西在 Swift/Xcode 的最新版本中移动了吗?
您应该在 class
的顶部添加以下内容import AVFoundation
并确保 AVFoundation 在您的 "Link Binary with Libraries"
中好的,这是旧问题,我相信您现在已经解决了,但我 运行 遇到了同样的错误。问题是我正在为 Mac 构建,而 AVAudioSession(当前)仅适用于 iOS。