在 ios 中使用 AVAudioSession 时出错 [英] Error while using AVAudioSession in ios
问题描述
我使用了这些代码
- (void)viewDidLoad
{
[[AVAudioSession sharedInstance] setDelegate: self];
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryAmbient error: nil];
AudioSessionAddPropertyListener (
kAudioSessionProperty_AudioRouteChange,
audioRouteChangeListenerCallback,
self
);
NSError *activationError = nil;
[[AVAudioSession sharedInstance] setActive: YES error: &activationError];
}
和
void audioRouteChangeListenerCallback (void *inUserData, AudioSessionPropertyID inPropertyID, UInt32 inPropertyValueSize, const void *inPropertyValue ) {
// ensure that this callback was invoked for a route change
if (inPropertyID != kAudioSessionProperty_AudioRouteChange) return;
{
// Determines the reason for the route change, to ensure that it is not
// because of a category change.
CFDictionaryRef routeChangeDictionary = (CFDictionaryRef)inPropertyValue;
CFNumberRef routeChangeReasonRef = (CFNumberRef)CFDictionaryGetValue (routeChangeDictionary, CFSTR (kAudioSession_AudioRouteChangeKey_Reason) );
SInt32 routeChangeReason;
CFNumberGetValue (routeChangeReasonRef, kCFNumberSInt32Type, &routeChangeReason);
if (routeChangeReason == kAudioSessionRouteChangeReason_OldDeviceUnavailable) {
//Handle Headset Unplugged
} else if (routeChangeReason == kAudioSessionRouteChangeReason_NewDeviceAvailable) {
//Handle Headset plugged in
}
}
}
检测音频插孔是否在我的项目中插入或拔出,但最终出现此错误
to detect if audio jack is plugged in or out in my project but I end up with this error
Undefined symbols for architecture armv7:
"_AVAudioSessionCategoryAmbient", referenced from:
-[ViewController viewDidLoad] in ViewController.o
"_OBJC_CLASS_$_AVAudioSession", referenced from:
objc-class-ref in ViewController.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
那么它有什么问题呢?我是 ios 的初学者,任何帮助将不胜感激.
So what is the issue in it? I'm a beginner in ios any help will be appreciated.
推荐答案
您没有将 AudioToolBox.Frameworks
添加到项目文件中.仔细检查您的项目文件设置..
You have miss to add AudioToolBox.Frameworks
to project file. Double check with your project file setting..
更新实际上错过了在项目构建阶段添加的 AVFoundation.Frameworks.
Update Actually missed AVFoundation.Frameworks to add in the build phase of project.
更新 2
尾随 s
已被删除.现在是 AudioToolBox.Framework
和 AVFoundation.Framework
Update 2
The trailing s
has been removed. Now it is AudioToolBox.Framework
and AVFoundation.Framework
这篇关于在 ios 中使用 AVAudioSession 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!