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
SBSAccelerometer - iPhone Development Wiki

SBSAccelerometer

From iPhone Development Wiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

SBSAccelerometer is a class in the SpringBoardServices.framework which can be used to create an own SBAccelerometerInterface, even from within SpringBoard.app. It's advantage above hooking "accelerometer"-methods in SpringBoard is that a delegate can be chosen.

Creating an instance of SBSAccelerometer and the delegate

Once an instance of SBSAccelerometer has been created you can use _checkIn to activate it; to deactivate it you send _checkOut. Example:

SBSAccelerometer *acc = [[SBSAccelerometer alloc] init];
acc.accelerometerEventsEnabled = YES;
acc.updateInterval = 0.1;
acc.xThreshold = 0.2;
acc.yThreshold = 0.2;
acc.zThreshold = 0.2;
acc._orientationEventsEnabled = NO;
acc.delegate = myAccDelegateInstance;
[acc _checkIn];

The delegate has to implement:

- (void)accelerometer:(SBSAccelerometer*)accelerometer didAccelerateWithTimeStamp:(NSTimeInterval)timestamp
	x:(CGFloat)x y:(CGFloat)y z:(CGFloat)z eventType:(unsigned)type

For orientation Events you need to enable _orientationEventsEnabled and implement the following method in your delegate:

- (void)accelerometer:(SBSAccelerometer*)accelerometer didChangeDeviceOrientation:(UIDeviceOrientation)newOrientation

References