I've included the CoreMotion framework in my project and imported the CoreMotion framework in the header of my view controller:
#import <CoreMotion/CoreMotion.h>
Then in -viewDidLoad I have this simple test code which I run on an 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 the project on the device and move it around, I never get a "foo" log. Also, I tried setting a breakpoint in the motion handler block and it never halts there. But I do get the "merde!" log, so this code is definitely executed.
Why is core motion not calling my handler? My iPhone 4 is functional. Accelerometers and gyro work perfectly in other apps. There is no hardware bug.