有没有办法在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, NULL);
AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &propertySize, &state);
if(CFStringGetLength(state) > 0)
return NO;
else
return YES;
}
答案 0 :(得分:14)
检查此帖子 - Detecting the iPhone's Ring / Silent / Mute switch using AVAudioPlayer not working?
此API - SoundSwitch
工作原理:
享受!