Maury Markowitz
Maury Markowitz

Reputation: 9279

AVAudioSession unknown

I'm, trying to use AVAudioSession in my Swift SpriteKit app. I am getting weird "undeclared type" problems. For instance...

import AVFoundation
var audioSession:AVAudioSession {
    return AVAudioSession.sharedInstance()
}

This returns an error on the first instance of AVAudioSession,Use of undeclared type 'AVAudioSession'. Later in my code I have this line...

import AVFoundation
    override func didMoveToView(view: SKView) {
        var titleError:NSError?
        audioSession.setCategory(AVAudioSessionCategoryPlayback, error: &error)
...

Which returns the same error on AVAudioSessionCategoryPlayback. Did this stuff move in recent versions of Swift/Xcode?

Upvotes: 2

Views: 4993

Answers (2)

John Scalo
John Scalo

Reputation: 3401

OK this is old and I'm sure you've solved it by now, but I just ran across the same error. The issue was that I was building for Mac while AVAudioSession is (currently) only available for iOS.

Source: https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVAudioSession_ClassReference/

Upvotes: 7

jfgrang
jfgrang

Reputation: 1178

You should add the following at the top of your class

import AVFoundation

and make sure AVFoundation is in your "Link Binary with Libraries"

Upvotes: 6

Related Questions