检测iPhone / iPod Touch配件 [英] Detecting iPhone/iPod Touch Accessories

查看:135
本文介绍了检测iPhone / iPod Touch配件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以检测iPod Touch / iPhone是否连接了耳机或其他配件?

Is it possible to detect if the iPod Touch/iPhone has any headphones or other accessories connected to it?

我正在构建一个需要麦克风的应用程序,并且需要知道iSomething是否有连接,或者通过底座连接,或者使用耳机端口,例如Apple的内置耳机/麦克风配件。

I'm building an app that requires a microphone, and need to know if the "iSomething" has one connected or not, either via the dock connection, or using the headphone port, such as with the inline headphone/microphone accessory from Apple.

推荐答案

终于找到了它 - 在初始化Audio Session对象之后, - AudioSessionInitialize() - 你可以调用AudioSessionGetProperty,并获得kAudioSessionProperty_AudioInputAvailable的值。

Finally found it - After initializing the Audio Session object, - AudioSessionInitialize() - you can make a call to AudioSessionGetProperty, and get the value of kAudioSessionProperty_AudioInputAvailable.

AudioSessionInitialize(NULL, NULL, NULL, NULL);    
UInt32 propertySize, micConnected;
    AudioSessionGetProperty(kAudioSessionProperty_AudioInputAvailable, &propertySize, &micConnected);
    [self updateMicStatus:micConnected]; // user-created method

根据音频会话服务的文档,应使用此方法而不是使用设备型号(iPhone与iPod Touch)确定是否可以使用音频输入。您还可以设置回调函数以通过AudioSessionAddPropertyListener()监视对此属性的更改。

According to the docs for Audio Session Services, this should be used rather than using the device model (iPhone vs. iPod Touch) to determine if an audio input is available to use. You can also set up a callback function to monitor changes to this property via AudioSessionAddPropertyListener().

如果此属性也适用于通过Dock连接器连接的设备,则还不确定但它似乎适用于耳机插孔。

Not sure yet if this property also applies to devices connected via the Dock connector, but it appears to work for the headphone jack.

这篇关于检测iPhone / iPod Touch配件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆