且构网

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

如何检测iphone是否处于静音模式

更新时间:2022-04-09 22:34:51

Pirripli 的代码不工作的原因是模拟器不支持测试,代码没有检查错误.更正后的代码如下所示:

The reason Pirripli's code does not work is that the simulator does not support the test and the code does not check for errors. Corrected code would look like:

CFStringRef state = nil;
UInt32 propertySize = sizeof(CFStringRef);
AudioSessionInitialize(NULL, NULL, NULL, NULL);
OSStatus status = AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &propertySize, &state);

if (status == kAudioSessionNoError)
{
    return (CFStringGetLength(state) == 0);   // YES = silent
}
return NO;