2017-03-20 4 views
3

電話がサイレントモードであるかどうかを検出する必要があります。 old waynew way(.cafファイルを再生しています)が見つかりましたが、正しく動作していませんでした。古い方法では廃止予定のツールが使用され、新しい方法ではどちらの場合も常に「いいえ」を指定します(サイレントモードではなく)。iOS - サイレントモードの検出

この時点で、誰でも何かを提案できますか?

+0

このhttp://stackoverflow.com/questions/35284722/how-can-i-detect-whether-an-を見ますios-device-is-in-silent-mode-or-not –

+0

あなたの答えはここにあります:http://stackoverflow.com/questions/287543/how-to-programmatically-sense-the-iphone-mute-switch – sschunara

+0

[iPhoneの検出方法はサイレントモードです](http://stackoverflow.com/questions/833304/how-to-detect-iphone-is-on-silent-mode) – iOS

答えて

0

以下のソリューションを試してみて、それがあなたのために働くなら、私に知らせて:

-(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; 

    } 
+1

私が何度も話したように、AudioSessionInitializeメソッドとgetPropertyメソッドはすべて非推奨です。どちらの方法(サイレントかどうか)ではNOを返します。 – anyName

+0

これ以上動作しません。 – user3427013

関連する問題