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
m (Created page with 'SBAccelerometerInterface is a singleton class that can deliver accelerometer events to registered clients. == Turn on accelerometer events within SpringBoard == When the Sp…')
 
m (→‎References: IPFHeader replacement)
 
(4 intermediate revisions by one other user not shown)
Line 1: Line 1:
[[SBAccelerometerInterface]] is a singleton class that can deliver accelerometer events to registered clients.  
[[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 ==
== Turn on accelerometer events within SpringBoard ==
Line 9: Line 9:
client.updateInterval = 0.1;  // set to 0 to turn off.
client.updateInterval = 0.1;  // set to 0 to turn off.
[interface updateSettings];
[interface updateSettings];
</source>
To obtain the current orientation, listen to the <tt>com.apple.springboard.rawOrientation</tt> Darwin notification and use the code below to obtain the orientation:
<source lang="c">
int token;
uint64_t state;
notify_register_check("com.apple.springboard.rawOrientation", &token);
notify_get_state(token, &state);
notify_cancel(token);
UIDeviceOrientation orientation = state;
</source>
</source>


== References ==
== References ==
{{IPFHeader|SpringBoard|.app}}
 
* Header: http://github.com/kennytm/iphone-private-frameworks/blob/master/SpringBoard/SBAccelerometerInterface.h
{{occlass|library=SpringBoard.app|navbox=1}}

Latest revision as of 14:01, 11 August 2015

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

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