且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何确定iPhone是否处于静音模式?

更新时间:2021-12-28 00:22:47

CFStringRef state;
UInt32 propertySize = sizeof(CFStringRef);
AudioSessionInitialize(NULL, NULL, NULL, NULL);
AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &propertySize, &state);
if(CFStringGetLength(state) == 0)
{
    //SILENT

}
else
{
    //NOT SILENT

}

如果状态字符串为空,那么电话静音 - 否则手机有音频输出

If the state string is empty then the phone is on silent - otherwise the phone has an audio output

编辑:

记得添加AudioToolbox框架和进口。 - Thomas Clayson

remember to add the AudioToolbox framework and import. – Thomas Clayson

答案取自(http://iphone-dev-tips.alterplay.com/2009/12/iphone-silent-mode-detection.html)

answer taken from (http://iphone-dev-tips.alterplay.com/2009/12/iphone-silent-mode-detection.html)