简体   繁体   English

iOS Objective-C 在 VoiceOver 处于活动状态时关闭接近监控

[英]iOS Objective-C Turn off Proximity Monitoring while VoiceOver is active

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.通常它会按预期工作,但是如果我打开 VoiceOver,如果接近传感器被覆盖,屏幕就会开始变黑。

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.仅供参考:我正在为弱视人士制作视频通话应用程序(使用 CallKit),他们的体验是,如果他们在通话过程中靠得太近屏幕,如果 VoiceOver 开启,屏幕就会变黑。

I tried installing an NSTimer to set proximityMonitoringEnabled to NO every second (as a poor workaround), also tried setting it YES and then NO.我尝试安装一个 NSTimer 以每秒将 ProximityMonitoringEnabled 设置为 NO(作为一种糟糕的解决方法),还尝试将其设置为 YES 然后设置为 NO。 It remains on NO, but screen still blacks out.它保持在 NO,但屏幕仍然黑屏。

In VoIP apps using Apple CallKit (like yours), you can enable and disable proximity monitoring during the call using AVAudioSession() class.在使用 Apple CallKit(如您的)的 VoIP 应用程序中,您可以在通话期间使用AVAudioSession()类启用和禁用接近度监控。 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 .默认情况下(如果您不使用 CallKit) proximityMonitoringEnabled实例属性为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 .默认值为 NO

However, if you use CallKit module, proximityMonitoringEnabled is not behaving as expected.但是,如果您使用 CallKit 模块, proximityMonitoringEnabled不会按预期运行。 By default a proximity monitoring is enabled – your app use for that a AVAudioSessionModeVoiceChat global variable:默认情况下启用接近度监控 - 您的应用程序使用AVAudioSessionModeVoiceChat全局变量:

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 .如果应用程序使用语音处理 I/O 音频单元并且尚未将其模式设置为其中一种聊天模式(语音、视频或游戏),则AVAudioSessionModeVoiceChat模式将被隐式设置


Disabling proximity monitoring in CallKit :在 CallKit 中禁用接近度监控:

Hence, if you want to disable a proximity monitoring just use a AVAudioSessionModeVideoChat global variable :因此,如果您想禁用接近度监控,只需使用AVAudioSessionModeVideoChat全局变量

const AVAudioSessionMode AVAudioSessionModeVideoChat;


Both variables work along with AVAudioSessionCategoryPlayAndRecord global variable:这两个变量与AVAudioSessionCategoryPlayAndRecord全局变量一起使用:

const AVAudioSessionCategory AVAudioSessionCategoryPlayAndRecord;

I think you have to change the session from AVAudioSessionModeVoiceChat to AVAudioSessionModeVideoChat .我认为您必须将会话从AVAudioSessionModeVoiceChat更改为AVAudioSessionModeVideoChat Then the proximity sensor should get ignored那么接近传感器应该被忽略

Something like that should do:这样的事情应该做:

[[AVAudioSession sharedInstance] setMode: AVAudioSessionModeVideoChat error:&err];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM