本文介绍了启用放在X code IOS禁用扬声器8.1同时呼吁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要启用扬声器,而从应用程序调用。我可以成功地启用它,但我不能禁用它。

I need to enable speaker while calling from app. I can successfully enable it but I am not able to disable it.

我使用这个方法:

[[UIDevice currentDevice] setProximityMonitoringEnabled:NO];
NSLog(@"%d",enable);

UInt32 route;
route = enable ? kAudioSessionOverrideAudioRoute_Speaker :
kAudioSessionOverrideAudioRoute_None;

AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,
                         sizeof(route), &route);

先谢谢了。

推荐答案

AudioSessionSetProperty是pcated德$ P $。
https://developer.apple.com/library/ios/documentation/audiotoolbox/reference/audiosessionservicesreference/index.html#//apple_ref/c/func/AudioSessionSetProperty

AudioSessionSetProperty is Deprecated.https://developer.apple.com/library/ios/documentation/audiotoolbox/reference/audiosessionservicesreference/index.html#//apple_ref/c/func/AudioSessionSetProperty

    - (void)setAudioOutputSpeaker:(BOOL)enabled
    {
    AVAudioSession *session =   [AVAudioSession sharedInstance];
    NSError *error;
    [session setCategory:AVAudioSessionCategoryPlayAndRecord error:&error];
    [session setMode:AVAudioSessionModeVoiceChat error:&error];
    if (enabled) // Enable speaker
        [session overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker error:&error];
    else // Disable speaker
        [session overrideOutputAudioPort:AVAudioSessionPortOverrideNone error:&error];
    [session setActive:YES error:&error];
    }

这篇关于启用放在X code IOS禁用扬声器8.1同时呼吁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 13:36