3

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.

1 Answer 1

1

I had very similar code running successfully, same applies to the available samples in the Event Handling Guide for iOS (there is only an appropriate one for gyro data). But there is one major difference:

All implementations hold their own reference to the opereation queue with operationQueue = [[NSOperationQueue currentQueue] retain]; or build their own. So hopefully this helps to get more than 'merde' in your logs ;-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.