I included the CoreMotion structure in my project and imported the CoreMotion structure into the header of my view controller:
#import <CoreMotion/CoreMotion.h>
Then in -viewDidLoad I have this simple test code that I run on iPhone 4 with iOS 4.3:
- (void)viewDidLoad {
[super viewDidLoad];
CMMotionManager *motionManager = [[CMMotionManager alloc] init];
[motionManager setDeviceMotionUpdateInterval:0.1];
CMDeviceMotionHandler motionHandler = ^(CMDeviceMotion *motion, NSError *error) {
NSLog(@"foo");
};
[motionManager startDeviceMotionUpdatesToQueue:[NSOperationQueue currentQueue] withHandler:motionHandler];
NSLog(@"merde!");
}
When I run a project on the device and move it, I never get the "foo" log. In addition, I tried to set a breakpoint in the motion handler block, and it never stops there. But I get "merde!" log, so this code is definitely executed.
Why doesn't the main engine call my handler? My iPhone 4 is functioning. Accelerometers and gyroscopes work great in other applications. Hardware error.