【问题标题】:Detect silent mode in iOS 7在 iOS 7 中检测静音模式
【发布时间】:2014-01-08 10:06:31
【问题描述】:

有什么方法可以检测 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;

   }

【问题讨论】:

标签: ios iphone ios7


【解决方案1】:

检查这个线程 - Detecting the iPhone's Ring / Silent / Mute switch using AVAudioPlayer not working?

还有这个 API - SoundSwitch

它是如何工作的:

  • 每秒播放 0.5 秒的音频文件(完成后..)
  • 检查播放声音所用的时间
  • 回调调用真的很快吗?未播放任何内容(静音开关已打开)

享受吧!

【讨论】:

猜你喜欢
  • 2017-08-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-19
  • 2014-04-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多