Iβm trying to detect when a user stumbles onto their iPhone on another object against when they simply shake their phone. I canβt get him to work perfectly as I want, because he either registers too many strokes, no strokes, or thinks that a shake is a blow.
Can someone see my code below and offer suggestions? I have to be sure that one or the other will happen.
// 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"); } }]; }
}
source share