2016-05-06 14 views
6

私は、ユーザーが自分のiPhoneを別のオブジェクトに突き当てたときと、自分の電話を振るだけのときを検出しようとしています。あまりにも多くのバンプやバンプが登録されていないか、シェイクがバンプだと思うので、私はそれが必要なときに完全に動作するようには見えません。CoreMotion Bump vs. iPhone Shake on

誰かが私のコードを見て、提案してくれますか?私はどちらか他が起こることを確かめる必要がある。

// SHAKING 
- (void) motionEnded: (UIEventSubtype) motion withEvent:(UIEvent *)event 
{ 
if (motion == UIEventSubtypeMotionShake) 
{ 
    [self setNumberOfShakes: [self numberOfShakes] + 1]; 
    [self reloadAllTapShakeData]; 
} 
} 

// TAPPING & BUMPING 
- (void) setupAccelerometerMonitoring 
{ 
[self setManager: [[CMMotionManager alloc] init]]; 
if ([[self manager] isDeviceMotionAvailable]) 
{ 
    [[self manager] setDeviceMotionUpdateInterval: 0.02]; 
    [[self manager] startDeviceMotionUpdatesToQueue: [NSOperationQueue mainQueue] withHandler: ^(CMDeviceMotion * _Nullable motion, NSError * _Nullable error) 
    { 
     //NSLog(@"x = %f | y = %f | z = %f", [motion userAcceleration].x, [motion userAcceleration].y, [motion userAcceleration].z); 
     if (([motion userAcceleration].x > .50 && [motion userAcceleration].x < 1) 
      || ([motion userAcceleration].y > .70 && [motion userAcceleration].x < 1) 
      || ([motion userAcceleration].z > .80 && [motion userAcceleration].z < 1)) 
     { 
      NSLog(@"TAPPED ON ANOTHER OBJECT"); 
     } 
    }]; 
} 

}

答えて

-1

私は、これは別の答えであると確信していますが、これはあなたを助けるかもしれません。

https://github.com/bumptech/bump-api-ios

それはgitのチェックアウト完全例えば

[[BumpClient sharedClient] setBumpEventBlock:^(bump_event event) { 
     switch(event) { 
      case BUMP_EVENT_BUMP: 
       NSLog(@"Bump detected."); 
       break; 
      case BUMP_EVENT_NO_MATCH: 
       NSLog(@"No match."); 
       break; 
    } 
}]; 

のようなブロック機能を持っています。

+0

APIはもう機能しません。 APIキーを持っていないのに、これはまだ動作しますか? –

+0

それを試してみてください。それはもはや互換性がありません。 –