.h file

// sensitivity level, 1.0 was way too sensitive 1.1 not enough
#define kAccelerationThreshold 1.07
#define kUpdateInterval (1.0f/10.0f)

@interface MainViewController : UIViewController <UIAccelerometerDelegate> {

.m file

- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {

if (fabsf(acceleration.x) > kAccelerationThreshold ||
fabsf(acceleration.y) > kAccelerationThreshold ||
fabsf(acceleration.z) > kAccelerationThreshold ) {

// whatever needs to happen here in this case select a sound and then play it
[self playSound: [self getSelectedSound] ];

}

}

this went in the - (void)viewDidLoad {

UIAccelerometer *accel = [UIAccelerometer sharedAccelerometer];
accel.delegate = self;
accel.updateInterval = kUpdateInterval;

Sorry, the comment form is closed at this time.

© 2012 James Border Suffusion theme by Sayontan Sinha