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
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)
If you use the correct audio session type, iOS will handle this for you:
来源:https://stackoverflow.com/questions/3880560/how-to-find-out-if-the-iphone-is-on-silent-mode