2013-03-12 22 views
0

我使用以下代碼在我的應用程序中使用coreMotion FrameWork來獲取搖動事件。此代碼工作完全正常的的iPod 5,但不工作的任何其他設備,即iPhone 4,iPhone 3GS,iPod的4我在iOS 6中嘗試了和5CoreMotion的startAccelerometerUpdates ::不提供搖動事件

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]; 
       } 
      }]; 

請諮詢可能是什麼問題。

回答

0

試試這個:

@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 

我是從here

它適用於所有iOS與3.0版++

+0

我不想因爲它們DONOT給予足夠的加速度數據使用UIResponder委託方法。無論如何感謝您的答案 – 2013-03-12 07:26:17