Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/html/extensions/Variables/includes/ExtVariables.php on line 198
AppleProxShim - iPhone Development Wiki


From iPhone Development Wiki
Kernel Extension IOHIDFamily
Parent Service AppleCT700
IOProviderClass AppleARMIICDevice
Primary Usage Page 65280
Primary Usage 8

AppleProxShim is the IOHIDService that controls the device's proximity sensor. By default, this service is enabled only from within applications that have called the high-level method -[UIApplication setProximitySensingEnabled:].

You can intercept the service to manually enable the proximity sensor and assign a callback action for the proximity events, even when on SpringBoard.

To turn on the sensor, you need to change the service's default ReportInterval from 0 to a higher number. For more information about IOHID, see IOHIDFamily

General characteristics

HIDServiceSupport Yes
Default ReportInterval 0


This example works only for the iPhone 4.

#include <IOKit/hid/IOHIDEventSystem.h>
#include <stdio.h>

void handle_event(void* target, void* refcon, IOHIDServiceRef service, IOHIDEventRef event) {
	if (IOHIDEventGetType(event) == kIOHIDEventTypeProximity) { // Proximity Event Received
		int proximityValue=IOHIDEventGetIntegerValue(event, (IOHIDEventField)kIOHIDEventFieldProximityDetectionMask); // Get the value of the ProximityChanged Field (0 or 64)
		// Call dimScreen on SpringBoard to simulate the original proximity effect, or use a reaction of your choice
		int (*SBSSpringBoardServerPort)() = (int (*)())dlsym(RTLD_DEFAULT, "SBSSpringBoardServerPort");
		int port = SBSSpringBoardServerPort(); 
		void (*_SBDimScreen)(int _port,BOOL shouldDim) = (void (*)(int _port,BOOL shouldDim))dlsym(RTLD_DEFAULT, "SBDimScreen");

		BOOL dim = proximityValue == 0 ? NO : YES;
		_SBDimScreen(port, dim); 

int main(int argc, char **argv) {
	// Create and open an event system.
	IOHIDEventSystemRef system = IOHIDEventSystemCreate(NULL);
	// Set the PrimaryUsagePage and PrimaryUsage that the AppleProxShim service uses
	int page = 65280;
	int usage = 8;

	// Create a dictionary to match the service with
	CFStringRef keys[2];
	CFNumberRef nums[2];
	keys[0] = CFStringCreateWithCString(0, "PrimaryUsagePage", 0);
	keys[1] = CFStringCreateWithCString(0, "PrimaryUsage", 0);
	nums[0] = CFNumberCreate(0, kCFNumberSInt32Type, &page);
	nums[1] = CFNumberCreate(0, kCFNumberSInt32Type, &usage);
	CFDictionaryRef dict = CFDictionaryCreate(0, (const void**)keys, (const void**)nums, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
	// Get the total of matching services with the above criteria
	CFArrayRef srvs = (CFArrayRef)IOHIDEventSystemCopyMatchingServices(system, dict, 0, 0, 0, 0);
	// Get the service
	IOHIDServiceRef serv = (IOHIDServiceRef)CFArrayGetValueAtIndex(srvs, 0);
	int interval = 1 ;

	// Set an interval of 1 , to activate the sensor  
	IOHIDServiceSetProperty((IOHIDServiceRef)serv, CFSTR("ReportInterval"), CFNumberCreate(0, kCFNumberSInt32Type, &interval));
	IOHIDEventSystemOpen(system, handle_event, NULL, NULL, NULL);
	printf("HID Event system should now be running. Hit enter to quit any time.\n");
	int defaultInterval = 0;
	IOHIDServiceSetProperty((IOHIDServiceRef)serv, CFSTR("ReportInterval"), CFNumberCreate(0, kCFNumberSInt32Type, &defaultInterval));

	IOHIDEventSystemClose(system, NULL);
	return 0;


The lockscreen has its own Dim Timer, so when in lockscreen the SBDimScreen event will only dim it, but will not undim. Test in SpringBoard, unlocked, for better results.

External links