我以前用过这个方法来检测静音开关是否开启:
- (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;
}
这在我的 iPad 或 iPhone 上的 iOS5 中不再有效。这是一个已知的问题?我无法在堆栈溢出或 Apple 开发论坛上找到任何答案。
希望你能帮助...
最佳答案
自 iOS 5 以来,我们将无法再检测静音开关状态...
Apple 的答案在已接受的答案中:Detecting the iPhone's Ring / Silent / Mute switch using AVAudioPlayer not working?
关于iphone - 在 iOS5 中检测静音模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7798891/