tags:

views:

72

answers:

1

Hi every one for some reasons i can't use shake API , so iam using shake device via accelerometer , but i don't why iPhone 4 , iPad do not support this code !!! but works on all devices .. i don't know what's going on ! here is my code :

#define kAccelerationThreshold        2.2
#define kUpdateInterval               (1.0f/10.0f)

@interface info : UIViewController  <UIAccelerometerDelegate> {

}
@end

~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~

@implementation info


- (void)viewDidLoad {
    UIAccelerometer *accel = [UIAccelerometer sharedAccelerometer];
    accel.delegate = self;
    accel.updateInterval = kUpdateInterval;


    [super viewDidLoad];
}


#pragma mark -
- (void)accelerometer:(UIAccelerometer *)accelerometer 
        didAccelerate:(UIAcceleration *)acceleration {
   {
        if (acceleration.x > kAccelerationThreshold 
            || acceleration.y > kAccelerationThreshold
            || acceleration.z > kAccelerationThreshold) {

//What do you want to do !

                self.view.backgroundColor = [UIColor orangeColor];

        }
    }
}
A: 

If you can't use the shake API on your iPhone, you probably haven't set your view controller as the first responder on viewDidAppear. Implement this method on your view controller:

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    [self becomeFirstResponder];
}

Now you will be able to use the shake API. Hope that helps :)

Fernando Valente
no ! the API works fine :) i don't have any problem whit that . thank you
Momeks