2016-05-06 27 views
6

Bir kullanıcının iPhone'unu başka bir nesnede ne zaman kullandığını algılamaya çalışırken, telefonlarını salladığında. İstediğim kadar mükemmel çalışmasını sağlayamıyorum, çünkü ya çok fazla çarpma, çarpma ya da bir sarsıntı yumru olduğunu düşünüyor.CoreMotion Bump vs. iPhone üzerinde Sarsıntı

Birisi aşağıdaki koduma bakıp öneri sunabilir mi? Birinin ya da diğerinin olduğundan emin olmalıyım.

// 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"); 
     } 
    }]; 
} 

}

cevap

-1

Bu farklı bir cevaptır eminim ama bu size yardımcı olabilir.

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

Bu tam bir örnek satın alma için

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

git gibi bir blok işlevi vardır.

+0

Onların API'si artık çalışmıyor mu? Bir API anahtarı olmaması, bu hala işe yarayacak mı? –

+0

Bunu denedim. Artık uyumlu değil. –