在iOS 7中检测静音模式 [英] Detect silent mode in iOS 7
本文介绍了在iOS 7中检测静音模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法在iOS 7中检测静音模式?
is there any way to detect silent mode in iOS 7?
以下代码不适用于iOS 5或更高版本
the following code does not work for iOS 5 or later version
-(BOOL)silenced {
#if TARGET_IPHONE_SIMULATOR
// return NO in simulator. Code causes crashes for some reason.
return NO;
#endif
CFStringRef state;
UInt32 propertySize = sizeof(CFStringRef);
AudioSessionInitialize(NULL, NULL, NULL, NULL);
AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &propertySize, &state);
if(CFStringGetLength(state) > 0)
return NO;
else
return YES;
}
推荐答案
检查这个线程 - 检测iPhone的响铃/静音/静音使用AVAudioPlayer切换不起作用?
Check this thread - Detecting the iPhone's Ring / Silent / Mute switch using AVAudioPlayer not working?
此API - SoundSwitch
工作原理:
- 播放每秒0.5秒的音频文件(完成后...)
- 检查播放声音需要多长时间
- 称为真正快速的回叫?没有播放(静音开关打开)
享受!
这篇关于在iOS 7中检测静音模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文