如何检测iPhone是在无声模式 [英] How to detect iphone is on silent mode
本文介绍了如何检测iPhone是在无声模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我开发的应用程序。在这我想通过代码来检测,是iPhone在静音模式或不呢?。我用用可可的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.
如果有人知道它请回复。
If anyone knows it kindly reply.
推荐答案
原因Pirripli的code不起作用的是,模拟器不支持试验和code错误不检查。更正code看起来像:
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屋!
查看全文