有没有办法在iOS 7中检测静音模式?
以下代码不适用于iOS 5或更高版本
-(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);
AudioSessionGetProperty(kAudioSessionProperty_AudioRoute,&propertySize,&state);
if(CFStringGetLength(state) > 0)
return NO;
else
return YES;
}
解决方法
检查这个帖子 –
Detecting the iPhone’s Ring / Silent / Mute switch using AVAudioPlayer not working?
而这个API – SoundSwitch
这个怎么运作:
>播放0.5秒的音频文件,每秒(完成后)
>检查播放声音所需的时间
>回调叫真快?没有播放(静音开关打开)
请享用!