6

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.

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
Dombi Bence
  • 746
  • 7
  • 23

2 Answers2

2

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 is OFF.

@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.

Disabling proximity monitoring in CallKit :

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;
Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
  • I already use this setting, and it's still not working properly. – Dombi Bence Dec 13 '19 at 10:05
  • Could you tell me what you mean saying `still not working properly`? – Andy Jazz Dec 13 '19 at 10:08
  • I had tried this before, and it didn't fix the problem. The screen still blacks out when the user leans too close. – Dombi Bence Dec 13 '19 at 10:28
  • Sorry for being late into this question. What I think you are overlooking in your answer, Andy, is the use of voice-over. Your solution is correct as long as voice-over is not activated. If you activate voice-over, however, the screen will again go blank even if you use video chat mode. – Anders Gustafsson Dec 11 '20 at 17:31
0

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];
Tristan R.
  • 61
  • 5