Reputation: 788
I would like to disable Proximity Monitoring, so that screen remains always ON, not matter how close something is to the sensor.
I tried it by using:
UIDevice.currentDevice.proximityMonitoringEnabled = NO;
Normally it is working as expected, however if I turn on VoiceOver, screen begins to black out if proximity sensor is covered.
FYI: I am making Video Call app (using CallKit) for people with low vision, and what they experience is that if they lean too close to the screen during a call, screen blacks out if VoiceOver is on.
I tried installing an NSTimer to set proximityMonitoringEnabled to NO every second (as a poor workaround), also tried setting it YES and then NO. It remains on NO, but screen still blacks out.
Upvotes: 6
Views: 1489
Reputation: 58043
In VoIP apps using Apple CallKit (like yours), you can enable and disable proximity monitoring during the call using
AVAudioSession()
class. It's a known feature when a proximity sensor is triggered and a screen is dimmed while approaching user's face.By default (if you're not using CallKit)
proximityMonitoringEnabled
instance property isOFF
.
@property(nonatomic, getter=isProximityMonitoringEnabled) BOOL proximityMonitoringEnabled;
// or
UIDevice.currentDevice.proximityMonitoringEnabled = NO; // DEFAULT VALUE
Apple's developer documentation says:
Enable proximity monitoring only when your application needs to be notified of changes to the proximity state. Otherwise, disable proximity monitoring. The default value is NO.
However, if you use CallKit module, proximityMonitoringEnabled
is not behaving as expected. By default a proximity monitoring is enabled – your app use for that a AVAudioSessionModeVoiceChat global variable:
const AVAudioSessionMode AVAudioSessionModeVoiceChat; // DEFAULT VALUE
Here's what developer documentation says here:
If an app uses the Voice-Processing I/O audio unit and has not set its mode to one of the chat modes (voice, video, or game),
AVAudioSessionModeVoiceChat
mode will be set implicitly.
Hence, if you want to disable a proximity monitoring just use a AVAudioSessionModeVideoChat global variable:
const AVAudioSessionMode AVAudioSessionModeVideoChat;
Both variables work along with AVAudioSessionCategoryPlayAndRecord global variable:
const AVAudioSessionCategory AVAudioSessionCategoryPlayAndRecord;
Upvotes: 2
Reputation: 71
I think you have to change the session from AVAudioSessionModeVoiceChat
to AVAudioSessionModeVideoChat
. Then the proximity sensor should get ignored
Something like that should do:
[[AVAudioSession sharedInstance] setMode: AVAudioSessionModeVideoChat error:&err];
Upvotes: 0