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

SBSAccelerometer: Difference between revisions

From iPhone Development Wiki
No edit summary
(Proper navboxification.)
Line 30: Line 30:
* Header: http://github.com/kennytm/iphone-private-frameworks/blob/master/SpringBoardServices/SBSAccelerometer.h
* Header: http://github.com/kennytm/iphone-private-frameworks/blob/master/SpringBoardServices/SBSAccelerometer.h


{{Navbox Classes}}
{{occlass|library=SpringBoardServices.framework|navbox=1}}
{{Navbox Frameworks}}

Revision as of 08:42, 13 June 2010

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 *theAcc = [[SBSAccelerometer alloc] init];
				theAcc.accelerometerEventsEnabled = YES;
				theAcc.updateInterval = 0.1;
				theAcc.xThreshold = 0.2;
				theAcc.yThreshold = 0.2;
				theAcc.zThreshold = 0.2;
                                theAcc._orientationEventsEnabled = NO;
				theAcc.delegate = myAccDelegateInstance;

				[theAcc _checkIn];

The delegate has to implement:

-(void)accelerometer:(SBSAccelerometer*)accelerometer didAccelerateWithTimeStamp:(NSTimeInterval)timestamp
				   x:(float)x y:(float)y z:(float)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