0

I am using following code to get shake events in my app using coreMotion FrameWork. This code works perfectly fine in iPod 5 but not working on any other device i.e. iPhone 4, 3gs, iPod 4. I tried in iOS 6 and 5.

NSOperationQueue *op = [[NSOperationQueue alloc] init];
        CMMotionManager *motionManager = [(AppDelegate *)[[UIApplication sharedApplication] delegate] sharedMotionManager];

            motionManager.deviceMotionUpdateInterval = 1;
            [motionManager startAccelerometerUpdatesToQueue:op withHandler:^(CMAccelerometerData *accelerometerData, NSError *error)
             {
                 if(error)
                 {
                     NSLog(@"%@", [error localizedDescription]);
                 }
                 else
                 {
                     [self calculateWithThreshold:accelerometerData];
                 }
             }];

Please advice what could be the problem.

abdus.me
  • 1,819
  • 22
  • 34

1 Answers1

0

Try this:

@implementation ShakingView

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
if ( event.subtype == UIEventSubtypeMotionShake )
{
    // Put in code here to handle shake
}

if ( [super respondsToSelector:@selector(motionEnded:withEvent:)] )
    [super motionEnded:motion withEvent:event];
}

- (BOOL)canBecomeFirstResponder
{ return YES; }

@end

I got it from here.

It works with all iOS with version 3.0++

Community
  • 1
  • 1
Thanakron Tandavas
  • 5,615
  • 5
  • 28
  • 41
  • I dont want to use UIResponder delegate methods as they donot give enough acceleration data. Thanks for the answer anyways – abdus.me Mar 12 '13 at 07:26