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
(Proper navboxification.)
m (Formatting)
 
Line 1: Line 1:
[[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.
[[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==
== Creating an instance of SBSAccelerometer and the delegate ==
 
Once an instance of SBSAccelerometer has been created you can use <tt>_checkIn</tt> to activate it; to deactivate it you send <tt>_checkOut</tt>. Example:
Once an instance of SBSAccelerometer has been created you can use <tt>_checkIn</tt> to activate it; to deactivate it you send <tt>_checkOut</tt>. Example:
<source lang="objc">
<source lang="objc">
SBSAccelerometer *theAcc = [[SBSAccelerometer alloc] init];
SBSAccelerometer *acc = [[SBSAccelerometer alloc] init];
theAcc.accelerometerEventsEnabled = YES;
acc.accelerometerEventsEnabled = YES;
theAcc.updateInterval = 0.1;
acc.updateInterval = 0.1;
theAcc.xThreshold = 0.2;
acc.xThreshold = 0.2;
theAcc.yThreshold = 0.2;
acc.yThreshold = 0.2;
theAcc.zThreshold = 0.2;
acc.zThreshold = 0.2;
                                theAcc._orientationEventsEnabled = NO;
acc._orientationEventsEnabled = NO;
theAcc.delegate = myAccDelegateInstance;
acc.delegate = myAccDelegateInstance;
 
[acc _checkIn];
[theAcc _checkIn];
</source>
</source>


The delegate has to implement:
The delegate has to implement:
<source lang="objc">
<source lang="objc">
-(void)accelerometer:(SBSAccelerometer*)accelerometer didAccelerateWithTimeStamp:(NSTimeInterval)timestamp
- (void)accelerometer:(SBSAccelerometer*)accelerometer didAccelerateWithTimeStamp:(NSTimeInterval)timestamp
  x:(float)x y:(float)y z:(float)z eventType:(unsigned)type
x:(CGFloat)x y:(CGFloat)y z:(CGFloat)z eventType:(unsigned)type
</source>
</source>


For orientation Events you need to enable <tt>_orientationEventsEnabled</tt> and implement the following method in your delegate:
For orientation Events you need to enable <tt>_orientationEventsEnabled</tt> and implement the following method in your delegate:
<source lang="objc">
<source lang="objc">
-(void)accelerometer:(SBSAccelerometer*)accelerometer didChangeDeviceOrientation:(UIDeviceOrientation)newOrientation
- (void)accelerometer:(SBSAccelerometer*)accelerometer didChangeDeviceOrientation:(UIDeviceOrientation)newOrientation
</source>
</source>


== References ==
== References ==
<references/>
* 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


{{occlass|library=SpringBoardServices.framework|navbox=1}}
{{occlass|library=SpringBoardServices.framework|navbox=1}}

Latest revision as of 14:36, 11 August 2015

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