Does accelerometer work for iphone / ipad simulator?

From what I can tell, my app is supposed to fire accelerometer events while I'm using the iPad simulator in Xcode but it isn't.

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

My code looks like this:

.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 it look right?

+2


a source to share


2 answers


There is no accelerator in the simulator.

The "Hardware → Shake Gesture" is generated by directly sending a UIEvent to the active application.



Although Shake Gesture is implemented using an on-device accelerator, conceptually they represent two different types of user input - gesture is an event, acceleration is continuous change. Thus, the Shake Gesture menu item exists for applications that only use such a gesture (for example, Shake to Undo), but it is not necessary to know the exact acceleration vector.

+5


a source


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



+1


a source







All Articles