如何确定iPhone是否处于静音模式? [英] How to find out if the iPhone is on silent mode?

查看:446
本文介绍了如何确定iPhone是否处于静音模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个邮寄申请。如果用户成功发送邮件,那么我需要通知邮件已成功发送。为此,我需要知道他的手机是否处于静音模式
(在这种情况下会有'振动')或常规模式(在这种情况下会有'嘟嘟声')。任何人都可以帮我吗?

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?

提前致谢

推荐答案

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)

这篇关于如何确定iPhone是否处于静音模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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