react-native-incall-manager
react-native-incall-manager copied to clipboard
Proximity sensor event not being fired
Hi,
I recently starting using this library with a project created with react native init
. I manually linked the library per the instructions.
I noticed the proximity sensor functionality was not working as expected. After calling InCallManager.start()
, the screen would not turn off when something was close to the sensor.
I checked the code in RNInCallManager.m
and found the function for starting the proximity sensor, and noticed _currentDevice.proximityMonitoringEnabled
set to NO
:
- (void)startProximitySensor
{
if (_isProximityRegistered) {
return;
}
NSLog(@"RNInCallManager.startProximitySensor()");
// _currentDevice.proximityMonitoringEnabled = YES;
_currentDevice.proximityMonitoringEnabled = NO;
// --- in case it didn't deallocate when ViewDidUnload
[self stopObserve:_proximityObserver
name:UIDeviceProximityStateDidChangeNotification
object:nil];
_proximityObserver = [self startObserve:UIDeviceProximityStateDidChangeNotification
object:_currentDevice
queue: nil
block:^(NSNotification *notification) {
BOOL state = _currentDevice.proximityState;
if (state != _proximityIsNear) {
NSLog(@"RNInCallManager.UIDeviceProximityStateDidChangeNotification(): isNear: %@", state ? @"YES" : @"NO");
_proximityIsNear = state;
[self sendEventWithName:@"Proximity" body:@{@"isNear": state ? @YES : @NO}];
}
}];
_isProximityRegistered = YES;
}
I uncommented the line setting it to YES
and commented the line setting it to NO
, and it starting working after rebuilding. However it now gives this warning:
-[UIApplication setExpectsFaceContact:inLandscape:] must be used from main thread only
I'm wondering if this is the actual fix or if I am missing something. Thanks!
try to import NativeModules and put the line in your JS code NativeModules.InCallManager.addListener('Proximity');
@tophed what did you end up doing here? The NativeModules solution above doesn't seem to work for me