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
SBAccelerometerInterface: Difference between revisions - iPhone Development Wiki

SBAccelerometerInterface: Difference between revisions

From iPhone Development Wiki
mNo edit summary
mNo edit summary
Line 1: Line 1:
[[SBAccelerometerInterface]] is a singleton class that can deliver accelerometer events to registered clients. This class is available starting from version 2.2.
[[SBAccelerometerInterface]] is a singleton class that can deliver accelerometer events to registered clients. This class is available starting from version 2.2.


== Turn on accelerometer events within SpringBoard ==
== Registering clients ==
{{function signature
|signature=-(void)clientRequestedAccelerometerEvents:(mach_port_t)port updateInterval:(NSTimeInterval)interval auditToken:(XXStruct_kUSYWB*)token;
|firmware=2.2
}}
{{function signature
|signature=-(void)clientRequestedAccelerometerEvents:(mach_port_t)port updateInterval:(NSTimeInterval)interval xThreshold:(float)xThreshold yThreshold:(float)yThreshold zThreshold:(float)zThreshold auditToken:(XXStruct_kUSYWB*)token;
|firmware=3.0 –
}}
 
Acceleration events are sent to [[SBAccelerometerClient]]s stored in the interface's private client list. To register a client, you have to go through the clientRequestedAccelerometerEvents:... method.
 
The ''x'' and ''y'' threshold should be set to 2, and the ''z'' threshold, 0. The auditToken could be kept NULL.
 
* ''TODO''
 
== Turn on accelerometer events within SpringBoard without client registration ==
When the SpringBoard is visible (i.e. the active [[SBDisplayStack|display stack]] is empty), the accelerometer will be turned off entirely. The following code can force accelerometer events to be reported even when there is no running apps:
When the SpringBoard is visible (i.e. the active [[SBDisplayStack|display stack]] is empty), the accelerometer will be turned off entirely. The following code can force accelerometer events to be reported even when there is no running apps:



Revision as of 08:35, 19 November 2009

SBAccelerometerInterface is a singleton class that can deliver accelerometer events to registered clients. This class is available starting from version 2.2.

Registering clients

Signature -(void)clientRequestedAccelerometerEvents:(mach_port_t)port updateInterval:(NSTimeInterval)interval auditToken:(XXStruct_kUSYWB*)token;
Available in 2.2
Signature -(void)clientRequestedAccelerometerEvents:(mach_port_t)port updateInterval:(NSTimeInterval)interval xThreshold:(float)xThreshold yThreshold:(float)yThreshold zThreshold:(float)zThreshold auditToken:(XXStruct_kUSYWB*)token;
Available in 3.0 –

Acceleration events are sent to SBAccelerometerClients stored in the interface's private client list. To register a client, you have to go through the clientRequestedAccelerometerEvents:... method.

The x and y threshold should be set to 2, and the z threshold, 0. The auditToken could be kept NULL.

  • TODO

Turn on accelerometer events within SpringBoard without client registration

When the SpringBoard is visible (i.e. the active display stack is empty), the accelerometer will be turned off entirely. The following code can force accelerometer events to be reported even when there is no running apps:

SBAccelerometerInterface* interface = [objc_getClass("SBAccelerometerInterface") sharedInstance];
SBAccelerometerClient* client = [[interface valueForKey:@"clients"] lastObject];
client.updateInterval = 0.1;  // set to 0 to turn off.
[interface updateSettings];

To obtain the current orientation, listen to the com.apple.springboard.rawOrientation Darwin notification and use the code below to obtain the orientation:

int token;
uint64_t state;
notify_register_check("com.apple.springboard.rawOrientation", &token);
notify_get_state(token, &state);
notify_cancel(token);
UIDeviceOrientation orientation = state;

References