【问题标题】:CoreMotion Bump vs. Shake on iPhoneiPhone 上的 CoreMotion Bump 与 Shake
【发布时间】:2016-05-06 23:13:53
【问题描述】:

我试图检测用户何时将他们的 iPhone 撞到另一个物体上,以及何时他们只是摇晃他们的手机。我似乎无法让它按我想要的那样完美地工作,因为它要么记录了太多的颠簸,没有颠簸,或者认为摇晃就是颠簸。

有人可以看看我下面的代码并提供建议吗?我需要确保其中一种发生。

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

}

【问题讨论】:

    标签: ios iphone core-motion


    【解决方案1】:

    我确信这是一个不同的答案,但这可能会对您有所帮助。

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

    它有一个类似的块功能

    [[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 的完整示例。

    【讨论】:

    • 他们的 API 不再工作了?没有 API 密钥,这还能用吗?
    • 试过了。它不再兼容。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-30
    • 1970-01-01
    • 2010-11-13
    • 1970-01-01
    • 2011-07-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多