iOS Question Proximity sensor in iOS

Augusto

Member
Licensed User
Longtime User
Hi to everybody,

I'm porting an app from B4A to B4i. In B4A I'm able to read the proximity sensor values with

B4X:
Dim proxSens As PhoneSensors
proxSens.Initialize2(proxSens.TYPE_PROXIMITY, 2)
proxSens.StartListening("ProxData")

Searching in the forum, I haven't found anything to do the same in B4i. Someone could help me?

Thanks
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
Sub EnableProximityMonitoring As Boolean
   Dim no As NativeObject
   no = no.Initialize("UIDevice").RunMethod("currentDevice", Null)
   no.SetField("proximityMonitoringEnabled", True)
   Return no.GetField("proximityMonitoringEnabled").AsBoolean
End Sub

Sub GetProximityState As Boolean
   Dim no As NativeObject
   no = no.Initialize("UIDevice").RunMethod("currentDevice", Null)
   Return no.GetField("proximityState").AsBoolean
End Sub
EnableProximityMonitoring returns true if proximity sensor is supported.
You can then check GetProximityState to get the state. Note that the screen will turn off automatically once you call EnableProximityMonitoring and the proximity sensor state is true.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…