Reputation: 25412
I am trying to set my AVAudioSession category based on whether or not audio is already playing, and after reading the Apple Dev Docs for AVAudioSession, I came up with this code, taken straight from their solution for what I was trying to accomplish:
UInt32 otherAudioIsPlaying; // 1
UInt32 propertySize = sizeof (otherAudioIsPlaying);
AudioSessionGetProperty ( // 2
kAudioSessionProperty_OtherAudioIsPlaying,
&propertySize,
&otherAudioIsPlaying
);
if (otherAudioIsPlaying) { // 3
[[AVAudioSession sharedInstance]
setCategory: AVAudioSessionCategoryAmbient
error: nil];
} else {
[[AVAudioSession sharedInstance]
setCategory: AVAudioSessionCategorySoloAmbient
error: nil];
}
Everything compiles correctly, but when I try to build and run the app, I get a Mach-O Linker error corresponding to AudioSessionGetProperty
.
Undefined symbols for architecture i386:
"_AudioSessionGetProperty", referenced from:
+[AppDelegate setAudioSession] in AppDelegate.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I imported the AVFoundation/AVFoundation.h
file into my AppDelegate (where the code is being executed). I also imported the AVFoundation framework into the project binary itself. Am I missing another framework that is required for this method? Why am I getting this error?
Upvotes: 1
Views: 1010
Reputation: 25412
For anyone else who may be having this problem:
In order to get the audiosession property in this manner, it requires the AudioToolbox
framework. Add that library to your project and import it and the linker error will go away.
Upvotes: 4