如何检测iphone是否处于静音模式 [英] How to detect iphone is on silent mode

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

问题描述

我正在开发一个应用程序.我想通过编码检测iPhone 是否处于静音模式?".我正在通过使用 Cocoa 和 Objective-C 来开发它.

I am developing an application. In that i want to detect through coding that "is iPhone on silent mode or not?". I am developing it by using cocoa with Objective-C.

如果有人知道请回复.

推荐答案

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;

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

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