gpt4 book ai didi

ios - 在 ios 中使用 AVAudioSession 时出错

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:50:46 31 4
gpt4 key购买 nike

我用过这些代码

- (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
}

}
}

在我的项目中检测音频插孔是否插入或拔出,​​但我最终遇到了这个错误

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 的初学者,我们将不胜感激。

最佳答案

您没有将 AudioToolBox.Frameworks 添加到项目文件中。仔细检查您的项目文件设置..

更新实际上错过了在项目构建阶段添加的 AVFoundation.Frameworks。

更新 2
尾随的 s 已被删除。现在是 AudioToolBox.FrameworkAVFoundation.Framework

关于ios - 在 ios 中使用 AVAudioSession 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16162145/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com