How to find out if the iPhone is on silent mode?

最后都变了- 提交于 2019-12-06 07:07:03

问题


I have a mailing application. If the user sends a mail successfully, then I need to notify that the mail was sent successfully. For that, I need to know if his phone is on silent mode (in which case there will be a 'vibrate') or regular mode (in which case there will be a 'beep'). Can anyone help me with it?

Thanks in advance


回答1:


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

EDIT:

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

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




回答2:


If you use the correct audio session type, iOS will handle this for you:

http://developer.apple.com/library/ios/#documentation/Audio/Conceptual/AudioSessionProgrammingGuide/Introduction/Introduction.html



来源:https://stackoverflow.com/questions/3880560/how-to-find-out-if-the-iphone-is-on-silent-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!