views:

617

answers:

3

From what I can tell, my app should be firing accelerometer events while Im using the iPad simulator in XCode, but its not.

I have googled around and it somewhat seems that the accelerometer is not implemented in the simulator, is this correct? If so, why on earth would they have a "Hardware->Shake Gesture" menu option?

My code is as follows:

.h file:

@interface MyViewController : UIViewController <UIPickerViewDataSource, UIPickerViewDelegate, UIAccelerometerDelegate>{
    UIAccelerometer *accelerometer;
    //...other stuff
}
@property (nonatomic, retain) UIAccelerometer *accelerometer;
@end

then the .m file:

@implementation MyViewController
@synthesize accelerometer;
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {
    NSLog(@"%@", [NSString stringWithFormat:@"%@%f", @"X: ", acceleration.x]);
    NSLog(@"%@", [NSString stringWithFormat:@"%@%f", @"Y: ", acceleration.y]);
    NSLog(@"%@", [NSString stringWithFormat:@"%@%f", @"Z: ", acceleration.z]);
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.accelerometer = [UIAccelerometer sharedAccelerometer];
    self.accelerometer.updateInterval = .1;
    self.accelerometer.delegate = self;
}
@end

Does this look right?

+1  A: 

Accelerometer does not work on iPhone/iPod Simulator. Neither "Hardware->Shake Gesture" use accelerometer nor the orientation change of safari on simulator.

Gaurav Verma
sorry, how exactly do i do that? :) still new to macs
Mark
actually, I miss read your post, sorry, I get it now, so why have the menu option?
Mark
+1  A: 
KennyTM
ahh, I see, well then thats actually what I want, so is my code wrong for that kind of implementation?
Mark
@Mark: Do you just want to handle to shake gestures? If so, see http://stackoverflow.com/questions/150446/how-do-i-detect-when-someone-shakes-an-iphone/1111983#1111983.
KennyTM
yeah, thanks ill take a look at that post...
Mark
A: 

why shake gesture is not working in Ipad Simulator

i did handle all the necessary events but still i dont get the shake effect

Ashish