When the app is running in foreground is works perfect.
p.s.
The iphone native phone app itself only does proximity check when you are in a call, I implemented the same behaviour in our version:
-(void) displayIncalViewforUser:(NSString*) username withDisplayName:(NSString*) displayName {
UIDevice *device = [UIDevice currentDevice];
device.proximityMonitoringEnabled = YES;
if (device.proximityMonitoringEnabled == YES) {
NSLog(@"Ok this device support proximity, and I just enabled it");
}
[hangup setEnabled:true];
if (displayName && [displayName length]>0) {
[peerLabel setText:displayName];
} else {
[peerLabel setText:username?username:@""];
}
[address setHidden:true];
[incallView setHidden:false];
}
-(void) displayDialerFromUI:(UIViewController*) viewCtrl forUser:(NSString*) username withDisplayName:(NSString*) displayName {
//cancel local notification, just in case
if ([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)]
&& [UIApplication sharedApplication].applicationState == UIApplicationStateBackground ) {
// cancel local notif if needed
[[UIApplication sharedApplication] cancelAllLocalNotifications];
} else {
if (mIncomingCallActionSheet) {
[mIncomingCallActionSheet dismissWithClickedButtonIndex:1 animated:true];
mIncomingCallActionSheet=nil;
}
}
[address setHidden:false];
if (username) {
[address setText:username];
} //else keep previous
[mDisplayName setText:displayName];
[incallView setHidden:true];
[call setEnabled:true];
[callDuration stop];
UIDevice *device = [UIDevice currentDevice];
device.proximityMonitoringEnabled = NO;
NSLog(@"Ok this device support proximity, and I just disabled it");
[peerLabel setText:@""];
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"firstlogindone_preference" ] == true) {
//first login case, dismmis first login view
[self dismissModalViewControllerAnimated:true];
};
[myTabBarController setSelectedIndex:DIALER_TAB_INDEX];
}